#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ fatal_error(char *);
scalar_t__ str_to_int(char *, int *);
int which_string_member(char *, char **, int);
int lookfor(char *s, int argc, char **argv) {
  int n;
  int i = which_string_member(s, argv, argc);
  if (i == -1)
    return 0;
  else if (argc > i + 1 && str_to_int(argv[i + 1], &n))
    return n;
  else {
    fatal_error("lookfor: bad arg list");
    return 0;
  }
}


x86 assembly (clang, -O0):
<lookfor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <which_string_member@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    116c <lookfor+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11bf <lookfor+0x8f>
mov    -0x14(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    11ac <lookfor+0x7c>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x24(%rbp),%rsi
call   1030 <str_to_int@plt>
cmp    $0x0,%rax
je     11ac <lookfor+0x7c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <lookfor+0x8f>
lea    0xe4d(%rip),%rdi
call   1040 <fatal_error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookfor>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdx,%rsi
mov    %ebp,%edx
call   1050 <which_string_member@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     117e <lookfor+0x4e>
add    $0x1,%eax
cmp    %ebp,%eax
jge    1172 <lookfor+0x42>
cltq
mov    (%rbx,%rax,8),%rdi
lea    0xc(%rsp),%rsi
call   1030 <str_to_int@plt>
test   %rax,%rax
je     1172 <lookfor+0x42>
mov    0xc(%rsp),%r14d
jmp    117e <lookfor+0x4e>
lea    0xe87(%rip),%rdi
call   1040 <fatal_error@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"lookfor: bad arg list\00"
define i32 @lookfor(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
%11 = load i8**, i8*** %7
%12 = load i32, i32* %6
%13 = call i32 @which_string_member(i8* %10, i8** %11, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %35
17: ; preds = %3
%18 = load i32, i32* %6
%19 = load i32, i32* %9
%20 = add nsw i32 %19, 1
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i8**, i8*** %7
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %23, i64 %26
%28 = load i8*, i8** %27
%29 = call i64 @str_to_int(i8* %28, i32* %8)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %35
33: ; preds = %22, %17
%34 = call i32 @fatal_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %35
35: ; preds = %33, %31, %16
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [22 x i8] c"lookfor: bad arg list\00"
define i32 @lookfor(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @which_string_member(i8* %0, i8** %2, i32 %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = add nuw nsw i32 %6, 1
%10 = icmp slt i32 %9, %1
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i8*, i8** %2, i64 %12
%14 = load i8*, i8** %13
%15 = call i64 @str_to_int(i8* %14, i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = load i32, i32* %4
br label %21
19: ; preds = %11, %8
%20 = call i32 @fatal_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %3, %19, %17
%22 = phi i32 [ %18, %17 ], [ 0, %19 ], [ 0, %3 ]
ret i32 %22
}