#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 const *,
                           char const *);
int /*<<< orphan*/ stderr;
int strtol(char const *, char **, int /*<<< orphan*/);
int cast_to_int(const char *key, const char *val, int *out) {
  char *end;
  *out = strtol(val, &end, 0);
  if (end == val || *end != '\0') {
    fprintf(stderr,
            "Error: key \"%s\" (\"%s\") did not cast "
            "properly to int\n",
            key, val);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cast_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1169 <cast_to_int+0x49>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1192 <cast_to_int+0x72>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <cast_to_int+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cast_to_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%r15)
mov    (%rsp),%rax
cmp    %rbx,%rax
je     1150 <cast_to_int+0x30>
cmpb   $0x0,(%rax)
je     1170 <cast_to_int+0x50>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to int\0A\00"
define i32 @cast_to_int(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%9 = load i8*, i8** %6
%10 = call i32 @strtol(i8* %9, i8** %8, i32 0)
%11 = load i32*, i32** %7
store i32 %10, i32* %11
%12 = load i8*, i8** %8
%13 = load i8*, i8** %6
%14 = icmp eq i8* %12, %13
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15, %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
store i32 -1, i32* %4
br label %26
25: ; preds = %15
store i32 0, i32* %4
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Error: key \22%s\22 (\22%s\22) did not cast properly to int\0A\00"
define i32 @cast_to_int(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtol(i8* %1, i8** %4, i32 0)
store i32 %6, i32* %2
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %1
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9, %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %15
15: ; preds = %9, %12
%16 = phi i32 [ -1, %12 ], [ 0, %9 ]
ret i32 %16
}