#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*/ strcmp(char *, char const *);
int get_flag(int argc, char *argv[], const char *name) {
  int i;
  for (i = argc - 1; i > 0; i--) {
    if (!strcmp(argv[i], name))
      return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1172 <get_flag+0x62>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    115f <get_flag+0x4f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1179 <get_flag+0x69>
jmp    1164 <get_flag+0x54>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    112c <get_flag+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_flag>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %edi,%r15d
lea    -0x1(%r15),%eax
lea    (%rsi,%rax,8),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x2,%r15d
jl     114f <get_flag+0x3f>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
add    $0xffffffff,%r15d
add    $0xfffffffffffffff8,%rbx
test   %eax,%eax
jne    1130 <get_flag+0x20>
jmp    1152 <get_flag+0x42>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_flag(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
%9 = load i32, i32* %5
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %8
br label %11
11: ; preds = %26, %3
%12 = load i32, i32* %8
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i8**, i8*** %6
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = load i8*, i8** %7
%21 = call i32 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %14
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %30
25: ; preds = %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %8
%28 = add nsw i32 %27, -1
store i32 %28, i32* %8
br label %11
29: ; preds = %11
store i32 0, i32* %4
br label %30
30: ; preds = %29, %23
%31 = load i32, i32* %4
ret i32 %31
}

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