#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 */
scalar_t__ strcmp(char *, char *);
int has_arg(int argc, char **argv, char *search) {
  for (int idx = 1; idx < argc; idx++) {
    if (strcmp(argv[idx], search) == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<has_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1174 <has_arg+0x64>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1161 <has_arg+0x51>
movl   $0x1,-0x4(%rbp)
jmp    117b <has_arg+0x6b>
jmp    1166 <has_arg+0x56>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <has_arg+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_arg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x2,%edi
jl     116c <has_arg+0x5c>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1167 <has_arg+0x57>
mov    %ebp,%ebp
mov    $0x2,%ecx
xchg   %ax,%ax
mov    %rcx,%rbx
cmp    %rcx,%rbp
je     115d <has_arg+0x4d>
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
jne    1140 <has_arg+0x30>
xor    %eax,%eax
cmp    %rbp,%rbx
setb   %al
jmp    116c <has_arg+0x5c>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @has_arg(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32 1, i32* %8
br label %9
9: ; preds = %24, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i8**, i8*** %6
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = load i8*, i8** %7
%20 = call i64 @strcmp(i8* %18, i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 1, i32* %4
br label %28
23: ; preds = %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %9
27: ; preds = %9
store i32 0, i32* %4
br label %28
28: ; preds = %27, %22
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @has_arg(i32 %0, i8** nocapture %1, i8* %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = zext i32 %0 to i64
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %5, %15
%13 = phi i64 [ %20, %15 ], [ 2, %5 ]
%14 = icmp eq i64 %13, %7
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = getelementptr inbounds i8*, i8** %1, i64 %13
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* %2)
%19 = icmp eq i64 %18, 0
%20 = add nuw nsw i64 %13, 1
br i1 %19, label %21, label %12
21: ; preds = %12, %15
%22 = icmp ult i64 %13, %6
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %21, %5, %3
%25 = phi i32 [ 0, %3 ], [ 1, %5 ], [ %23, %21 ]
ret i32 %25
}