#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 *);
int find_option(int, char **, char const *);
int read_int(int argc, char **argv, const char *option, int default_value) {
  int iplace = find_option(argc, argv, option);
  if (iplace >= 0 && iplace < argc - 1)
    return atoi(argv[iplace + 1]);
  return default_value;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <find_option@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     1182 <read_int+0x62>
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1182 <read_int+0x62>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    1188 <read_int+0x68>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <find_option@plt>
test   %eax,%eax
js     114c <read_int+0x2c>
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jge    114c <read_int+0x2c>
mov    %eax,%eax
mov    0x8(%rbx,%rax,8),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <atoi@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @read_int(i32 %0, i8** %1, i8* %2, i32 %3) {
%5 = tail call i32 @find_option(i32 %0, i8** %1, i8* %2)
%6 = icmp sgt i32 %5, -1
%7 = add nsw i32 %0, -1
%8 = icmp slt i32 %5, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %16
10: ; preds = %4
%11 = add nuw nsw i32 %5, 1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
br label %16
16: ; preds = %4, %10
%17 = phi i32 [ %15, %10 ], [ %3, %4 ]
ret i32 %17
}