#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*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int is_in_args(char *name, int index, int argc, char **argv) {
  int found = 0;
  char buffer[16];
  while (index < argc) {
    snprintf(buffer, 16, "%s", argv[index]);
    if (strncmp(name, buffer, strlen(argv[index])) == 0) {
      found = index;
      break;
    }
    index++;
  }
  return found;
}


x86 assembly (clang, -O0):
<is_in_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cd <is_in_args+0x9d>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x10,%esi
lea    0xe8b(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11bf <is_in_args+0x8f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <is_in_args+0x9d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <is_in_args+0x1d>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_in_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
cmp    %edx,%esi
jge    11b2 <is_in_args+0x82>
mov    %rdi,%r12
mov    %esi,0xc(%rsp)
movslq %esi,%rax
movslq %edx,%r13
lea    (%rcx,%rax,8),%r14
sub    %rax,%r13
xor    %ebx,%ebx
lea    0xe9f(%rip),%r15
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rcx
mov    %rbp,%rdi
mov    $0x10,%esi
mov    %r15,%rdx
call   1050 <snprintf@plt>
mov    (%r14,%rbx,8),%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11ac <is_in_args+0x7c>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <is_in_args+0x40>
xor    %eax,%eax
jmp    11b2 <is_in_args+0x82>
mov    0xc(%rsp),%eax
add    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @is_in_args(i8* %0, i32 %1, i32 %2, i8** nocapture %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = icmp slt i32 %1, %2
br i1 %7, label %8, label %25
8: ; preds = %4
%9 = sext i32 %1 to i64
%10 = sext i32 %2 to i64
br label %11
11: ; preds = %8, %20
%12 = phi i64 [ %9, %8 ], [ %21, %20 ]
%13 = getelementptr inbounds i8*, i8** %3, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @snprintf(i8* %6, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %13
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @strncmp(i8* %0, i8* %6, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = add nsw i64 %12, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %25, label %11
23: ; preds = %11
%24 = trunc i64 %12 to i32
br label %25
25: ; preds = %20, %23, %4
%26 = phi i32 [ 0, %4 ], [ %24, %23 ], [ 0, %20 ]
ret i32 %26
}