#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 */
struct argp_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ argp_error(struct argp_state const *, char *, ...);
long strtol(char const *, char **, int /*<<< orphan*/);
long arg_to_long(const struct argp_state *state, const char *arg) {
  char *end;
  long l = strtol(arg, &end, 0);
  if (!arg)
    argp_error(state, "An integer must be provided");
  if (!*arg || *end)
    argp_error(state, "`%s' is not an integer", arg);
  return l;
}


x86 assembly (clang, -O0):
<arg_to_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <arg_to_long+0x40>
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <argp_error@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     117d <arg_to_long+0x5d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1193 <arg_to_long+0x73>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <argp_error@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r15
test   %rbx,%rbx
je     114d <arg_to_long+0x2d>
cmpb   $0x0,(%rbx)
jne    1163 <arg_to_long+0x43>
jmp    116d <arg_to_long+0x4d>
lea    0xeac(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <argp_error@plt>
cmpb   $0x0,(%rbx)
je     116d <arg_to_long+0x4d>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1181 <arg_to_long+0x61>
lea    0xea8(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <argp_error@plt>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.argp_state = type { i32 }
@.str = [28 x i8] c"An integer must be provided\00"
@.str.1 = [23 x i8] c"`%s' is not an integer\00"
define i64 @arg_to_long(%struct.argp_state* %0, i8* %1) {
%3 = alloca %struct.argp_state*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store %struct.argp_state* %0, %struct.argp_state** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strtol(i8* %7, i8** %5, i32 0)
store i64 %8, i64* %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load %struct.argp_state*, %struct.argp_state** %3
%13 = call i32 (%struct.argp_state*, i8*, ...) @argp_error(%struct.argp_state* %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %5
%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 = %18, %14
%24 = load %struct.argp_state*, %struct.argp_state** %3
%25 = load i8*, i8** %4
%26 = call i32 (%struct.argp_state*, i8*, ...) @argp_error(%struct.argp_state* %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %18
%28 = load i64, i64* %6
ret i64 %28
}

LLVM IR (-O2):
%struct.argp_state = type { i32 }
@.str = [28 x i8] c"An integer must be provided\00"
@.str.1 = [23 x i8] c"`%s' is not an integer\00"
define i64 @arg_to_long(%struct.argp_state* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %1, i8** %3, i32 0)
%6 = icmp eq i8* %1, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (%struct.argp_state*, i8*, ...) @argp_error(%struct.argp_state* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12, %9
%17 = tail call i32 (%struct.argp_state*, i8*, ...) @argp_error(%struct.argp_state* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %18
18: ; preds = %16, %12
ret i64 %5
}