#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 */
long INT_MAX;
scalar_t__ errno;
int /*<<< orphan*/ show_usage(int);
long strtol(char *, char **, int);
int get_int(char *str, int base) {
  long v;
  char *endp;
  if (!str)
    show_usage(1);
  errno = 0;
  v = strtol(str, &endp, base);
  if (errno || *endp || v > INT_MAX)
    show_usage(1);
  return (int)v;
}


x86 assembly (clang, -O0):
<get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1144 <get_int+0x24>
mov    $0x1,%edi
call   1040 <show_usage@plt>
mov    0x2e8d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1030 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e6b(%rip),%rax
cmpq   $0x0,(%rax)
jne    119b <get_int+0x7b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119b <get_int+0x7b>
mov    -0x18(%rbp),%rax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
jle    11a5 <get_int+0x85>
mov    $0x1,%edi
call   1040 <show_usage@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
jne    113c <get_int+0x1c>
mov    $0x1,%edi
call   1040 <show_usage@plt>
mov    0x2e95(%rip),%r14
movq   $0x0,(%r14)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strtol@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r14)
je     1177 <get_int+0x57>
mov    $0x1,%edi
call   1040 <show_usage@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1162 <get_int+0x42>
mov    0x2e60(%rip),%rax
cmp    (%rax),%rbx
jle    116c <get_int+0x4c>
jmp    1162 <get_int+0x42>

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

LLVM IR (-O2):
@errno = global i64 0
@INT_MAX = global i64 0
define i32 @get_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @show_usage(i32 1)
br label %8
8: ; preds = %6, %2
store i64 0, i64* @errno
%9 = call i64 @strtol(i8* %0, i8** %3, i32 %1)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = load i64, i64* @INT_MAX
%17 = icmp sgt i64 %9, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %21
19: ; preds = %12, %8
%20 = tail call i32 @show_usage(i32 1)
br label %21
21: ; preds = %12, %19
%22 = trunc i64 %9 to i32
ret i32 %22
}