#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*/ get_str_flag(char ***, char, char **);
int strtol(char *, char **, int);
int /*<<< orphan*/ usage(char *, char *, char);
int get_int_flag(char ***args, char flag, int *val) {
  char *str, *end;
  if (!get_str_flag(args, flag, &str))
    return 0;
  *val = strtol(str, &end, 10);
  if (*end != '\0')
    usage("Argument %s to -%c is not an integer\n", str, flag);
  return 1;
}


x86 assembly (clang, -O0):
<get_int_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rdx
movsbl -0x11(%rbp),%esi
call   1030 <get_str_flag@plt>
cmp    $0x0,%eax
jne    116c <get_int_flag+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <get_int_flag+0x81>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11aa <get_int_flag+0x7a>
mov    -0x28(%rbp),%rsi
lea    0xe5f(%rip),%rdi
movsbl -0x11(%rbp),%edx
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int_flag>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rsp,%rdx
call   1030 <get_str_flag@plt>
test   %eax,%eax
je     1183 <get_int_flag+0x53>
mov    (%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
mov    $0x1,%ebp
cmpb   $0x0,(%rax)
je     1185 <get_int_flag+0x55>
mov    (%rsp),%rsi
movsbl %bl,%edx
lea    0xe84(%rip),%rdi
call   1050 <usage@plt>
jmp    1185 <get_int_flag+0x55>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Argument %s to -%c is not an integer\0A\00"
define i32 @get_int_flag(i8*** %0, i8 signext %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8***
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
store i8*** %0, i8**** %5
store i8 %1, i8* %6
store i32* %2, i32** %7
%10 = load i8***, i8**** %5
%11 = load i8, i8* %6
%12 = call i32 @get_str_flag(i8*** %10, i8 signext %11, i8** %8)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 0, i32* %4
br label %28
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = call i32 @strtol(i8* %16, i8** %9, i32 10)
%18 = load i32*, i32** %7
store i32 %17, i32* %18
%19 = load i8*, i8** %9
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i8*, i8** %8
%25 = load i8, i8* %6
%26 = call i32 @usage(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %24, i8 signext %25)
br label %27
27: ; preds = %23, %15
store i32 1, i32* %4
br label %28
28: ; preds = %27, %14
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [38 x i8] c"Argument %s to -%c is not an integer\0A\00"
define i32 @get_int_flag(i8*** %0, i8 signext %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = call i32 @get_str_flag(i8*** %0, i8 signext %1, i8** %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @strtol(i8* %11, i8** %5, i32 10)
store i32 %12, i32* %2
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = call i32 @usage(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %17, i8 signext %1)
br label %19
19: ; preds = %10, %16, %3
%20 = phi i32 [ 0, %3 ], [ 1, %16 ], [ 1, %10 ]
ret i32 %20
}