#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 sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int get_arg_int(int argc, char **argv, char *key, int *num) {
  int ret;
  int i;
  ret = -1;
  for (i = 0; i < argc; i++) {
    if (strcmp(argv[i], key) == 0) {
      ret = sscanf(argv[i + 1], "%d", num);
      ret = 0;
      break;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_arg_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b3 <get_arg_int+0x93>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11a0 <get_arg_int+0x80>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    11b3 <get_arg_int+0x93>
jmp    11a5 <get_arg_int+0x85>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1145 <get_arg_int+0x25>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
test   %edi,%edi
jle    1184 <get_arg_int+0x64>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116d <get_arg_int+0x4d>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <get_arg_int+0x30>
jmp    1184 <get_arg_int+0x64>
mov    0x8(%r13,%rbx,8),%rdi
lea    0xe87(%rip),%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
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):
@.str = [3 x i8] c"%d\00"
define i32 @get_arg_int(i32 %0, i8** %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32* %3, i32** %8
store i32 -1, i32* %9
store i32 0, i32* %10
br label %11
11: ; preds = %34, %4
%12 = load i32, i32* %10
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i8**, i8*** %6
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = load i8*, i8** %7
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %15
%25 = load i8**, i8*** %6
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
%31 = load i32*, i32** %8
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %31)
store i32 %32, i32* %9
store i32 0, i32* %9
br label %37
33: ; preds = %15
br label %34
34: ; preds = %33
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %11
37: ; preds = %24, %11
%38 = load i32, i32* %9
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @get_arg_int(i32 %0, i8** nocapture %1, i8* %2, i32* %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %22
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %20
%9 = phi i64 [ 0, %6 ], [ %14, %20 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* %2)
%13 = icmp eq i64 %12, 0
%14 = add nuw i64 %9, 1
br i1 %13, label %15, label %20
15: ; preds = %8
%16 = and i64 %14, 4294967295
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %22
20: ; preds = %8
%21 = icmp eq i64 %14, %7
br i1 %21, label %22, label %8
22: ; preds = %20, %4, %15
%23 = phi i32 [ 0, %15 ], [ -1, %4 ], [ -1, %20 ]
ret i32 %23
}