#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__ ERANGE;
long INT_MAX;
long INT_MIN;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ opt_err(char *);
long strtol(char *, char **, int);
int opt_store_int(char *arg, void *data) {
  char *end;
  long val;
  assert(arg && data);
  errno = 0;
  val = strtol(arg, &end, 10);
  if (end == arg || end[0])
    opt_err("the value of %s must be an integer");
  if (errno == ERANGE || val < INT_MIN || val > INT_MAX)
    opt_err("the value of %s is too large");
  *(int *)data = val;
  return 0;
}


x86 assembly (clang, -O0):
<opt_store_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x21(%rbp)
je     115b <opt_store_int+0x2b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    0x2e59(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11aa <opt_store_int+0x7a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b6 <opt_store_int+0x86>
lea    0xe4f(%rip),%rdi
call   1050 <opt_err@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
je     11f8 <opt_store_int+0xc8>
mov    -0x20(%rbp),%rax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
jl     11f8 <opt_store_int+0xc8>
mov    -0x20(%rbp),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
jle    1204 <opt_store_int+0xd4>
lea    0xe24(%rip),%rdi
call   1050 <opt_err@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_store_int>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    0x2e6d(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r15
mov    (%rsp),%rax
cmp    %rbx,%rax
je     1184 <opt_store_int+0x54>
cmpb   $0x0,(%rax)
je     1190 <opt_store_int+0x60>
lea    0xe75(%rip),%rdi
call   1050 <opt_err@plt>
mov    (%r12),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
je     11b8 <opt_store_int+0x88>
mov    0x2e39(%rip),%rax
cmp    (%rax),%r15
jl     11b8 <opt_store_int+0x88>
mov    0x2e35(%rip),%rax
cmp    (%rax),%r15
jle    11c4 <opt_store_int+0x94>
lea    0xe64(%rip),%rdi
call   1050 <opt_err@plt>
mov    %r15d,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [35 x i8] c"the value of %s must be an integer\00"
@ERANGE = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@.str.1 = [29 x i8] c"the value of %s is too large\00"
define i32 @opt_store_int(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ false, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i64 0, i64* @errno
%16 = load i8*, i8** %3
%17 = call i64 @strtol(i8* %16, i8** %5, i32 10)
store i64 %17, i64* %6
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %27, label %21
21: ; preds = %12
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21, %12
%28 = call i32 @opt_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = load i64, i64* @errno
%31 = load i64, i64* @ERANGE
%32 = icmp eq i64 %30, %31
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load i64, i64* %6
%35 = load i64, i64* @INT_MIN
%36 = icmp slt i64 %34, %35
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i64, i64* %6
%39 = load i64, i64* @INT_MAX
%40 = icmp sgt i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37, %33, %29
%42 = call i32 @opt_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = load i64, i64* %6
%45 = trunc i64 %44 to i32
%46 = load i8*, i8** %4
%47 = bitcast i8* %46 to i32*
store i32 %45, i32* %47
ret i32 0
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [35 x i8] c"the value of %s must be an integer\00"
@ERANGE = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@.str.1 = [29 x i8] c"the value of %s is too large\00"
define i32 @opt_store_int(i8* %0, i8* writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %1, null
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
store i64 0, i64* @errno
%10 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, %0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13, %2
%17 = tail call i32 @opt_err(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i64, i64* @errno
%20 = load i64, i64* @ERANGE
%21 = icmp eq i64 %19, %20
%22 = load i64, i64* @INT_MIN
%23 = icmp slt i64 %10, %22
%24 = select i1 %21, i1 true, i1 %23
%25 = load i64, i64* @INT_MAX
%26 = icmp sgt i64 %10, %25
%27 = select i1 %24, i1 true, i1 %26
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = tail call i32 @opt_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %18, %28
%31 = trunc i64 %10 to i32
%32 = bitcast i8* %1 to i32*
store i32 %31, i32* %32
ret i32 0
}