#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 atoi(char *);
scalar_t__ strcmp(char const *, char *);
int arg_get_int(int argc, char *argv[], const char *key, int *value) {
  int i = 0;
  for (i = 1; i < argc; i++) {
    if (strcmp(key, argv[i]) != 0) {
      continue;
    }
    if (argv[i + 1] == NULL) {
      return -1;
    }
    *value = atoi(argv[i + 1]);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<arg_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d1 <arg_get_int+0xb1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1175 <arg_get_int+0x55>
jmp    11c3 <arg_get_int+0xa3>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1199 <arg_get_int+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <arg_get_int+0xb8>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d8 <arg_get_int+0xb8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <arg_get_int+0x25>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_get_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
cmp    $0x2,%edi
jl     1182 <arg_get_int+0x62>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rsi
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116d <arg_get_int+0x4d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <arg_get_int+0x30>
jmp    1182 <arg_get_int+0x62>
mov    0x8(%r13,%rbx,8),%rdi
test   %rdi,%rdi
je     1182 <arg_get_int+0x62>
call   1040 <atoi@plt>
mov    %eax,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @arg_get_int(i32 %0, i8** %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32 0, i32* %10
store i32 1, i32* %10
br label %11
11: ; preds = %43, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %46
15: ; preds = %11
%16 = load i8*, i8** %8
%17 = load i8**, i8*** %7
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %16, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %15
br label %43
25: ; preds = %15
%26 = load i8**, i8*** %7
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
%31 = load i8*, i8** %30
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %25
store i32 -1, i32* %5
br label %47
34: ; preds = %25
%35 = load i8**, i8*** %7
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %35, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = load i32*, i32** %9
store i32 %41, i32* %42
store i32 0, i32* %5
br label %47
43: ; preds = %24
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %11
46: ; preds = %11
store i32 -1, i32* %5
br label %47
47: ; preds = %46, %34, %33
%48 = load i32, i32* %5
ret i32 %48
}

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