#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*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int get_arg_int(char **argv, int argi, int argc, int *pval, char *desc) {
  if (argc <= argi + 1) {
    fprintf(stderr, "%s:  Missing argument to %s.\n", argv[0], argv[argi]);
    return 0;
  }
  if (sscanf(argv[argi + 1], "%d", pval) != 1) {
    fprintf(stderr, "%s: Couldn't scan \"%s\" as %s.\n", argv[0],
            argv[argi + 1], desc);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<get_arg_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     1181 <get_arg_int+0x61>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <get_arg_int+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11ea <get_arg_int+0xca>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x28(%rbp),%r8
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <get_arg_int+0xd1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x1(%rsi),%eax
cmp    %edx,%eax
jge    1179 <get_arg_int+0x59>
mov    %r8,%r14
movslq %eax,%r15
mov    (%rbx,%r15,8),%rdi
lea    0xedc(%rip),%rsi
mov    %rcx,%rdx
call   1040 <sscanf@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
je     119c <get_arg_int+0x7c>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    (%rbx,%r15,8),%rcx
lea    0xeb6(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    119c <get_arg_int+0x7c>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
movslq %esi,%rax
mov    (%rbx,%rax,8),%rcx
lea    0xe6d(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"%s: Missing argument to %s.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"%s: Couldn't scan \22%s\22 as %s.\0A\00"
define i32 @get_arg_int(i8** %0, i32 %1, i32 %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
store i8** %0, i8*** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i8* %4, i8** %11
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = add nsw i32 %13, 1
%15 = icmp sle i32 %12, %14
br i1 %15, label %16, label %27
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %7
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %7
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %25)
store i32 0, i32* %6
br label %51
27: ; preds = %5
%28 = load i8**, i8*** %7
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
%33 = load i8*, i8** %32
%34 = load i32*, i32** %10
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %50
37: ; preds = %27
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %7
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %7
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
%47 = load i8*, i8** %46
%48 = load i8*, i8** %11
%49 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %47, i8* %48)
store i32 0, i32* %6
br label %51
50: ; preds = %27
store i32 1, i32* %6
br label %51
51: ; preds = %50, %37, %16
%52 = load i32, i32* %6
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"%s: Missing argument to %s.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"%s: Couldn't scan \22%s\22 as %s.\0A\00"
define i32 @get_arg_int(i8** nocapture %0, i32 %1, i32 %2, i32* %3, i8* %4) {
%6 = add nsw i32 %1, 1
%7 = icmp slt i32 %6, %2
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %0
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %13)
br label %26
15: ; preds = %5
%16 = sext i32 %6 to i64
%17 = getelementptr inbounds i8*, i8** %0, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%20 = icmp eq i32 %19, 1
br i1 %20, label %26, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %0
%24 = load i8*, i8** %17
%25 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24, i8* %4)
br label %26
26: ; preds = %15, %21, %8
%27 = phi i32 [ 0, %8 ], [ 0, %21 ], [ 1, %15 ]
ret i32 %27
}