#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 */
scalar_t__ errno;
long strtol(char *, char **, int /*<<< orphan*/);
int set_int(int *res, char *val) {
  long l;
  char *end;
  errno = 0;
  l = strtol(val, &end, 0);
  if (*end != '\0')
    return 1;
  if (errno != 0)
    return 1;
  *res = l;
  return 0;
}


x86 assembly (clang, -O0):
<set_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     115d <set_int+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    118d <set_int+0x7d>
mov    0x2e7c(%rip),%rax
cmpq   $0x0,(%rax)
je     117a <set_int+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    118d <set_int+0x7d>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
mov    0x2ebf(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
mov    $0x1,%eax
jne    1151 <set_int+0x41>
cmpq   $0x0,(%rbx)
jne    1151 <set_int+0x41>
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @set_int(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 0, i64* @errno
%8 = load i8*, i8** %5
%9 = call i64 @strtol(i8* %8, i8** %7, i32 0)
store i64 %9, i64* %6
%10 = load i8*, i8** %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %23
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 1, i32* %3
br label %23
19: ; preds = %15
%20 = load i64, i64* %6
%21 = trunc i64 %20 to i32
%22 = load i32*, i32** %4
store i32 %21, i32* %22
store i32 0, i32* %3
br label %23
23: ; preds = %19, %18, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @set_int(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %1, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = trunc i64 %5 to i32
store i32 %13, i32* %0
br label %14
14: ; preds = %2, %12
%15 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %15
}