#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;
long INT_MIN;
long LONG_MAX;
long LONG_MIN;
char *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, long);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
long strtol(char *, char **, int);
int set_state(char *state) {
  char *rest = calloc(16, sizeof(char));
  long int temp_state = strtol(state, (char **)&rest, 10);
  if (temp_state >= INT_MIN && temp_state <= INT_MAX && state != NULL &&
      strcmp(state, rest) != 0)
    return temp_state;
  else {
    if (temp_state == LONG_MIN || temp_state == LONG_MAX)
      perror("Bla");
    fputs("Invalid input for state. It must be a number between ", stderr);
    fprintf(stderr, "%d and %d\n", INT_MIN, INT_MAX);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<set_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
jl     11f9 <set_state+0x89>
mov    -0x18(%rbp),%rax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%rax
jg     11f9 <set_state+0x89>
cmpq   $0x0,-0x8(%rbp)
je     11f9 <set_state+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f9 <set_state+0x89>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%rax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <set_state+0xb1>
mov    -0x18(%rbp),%rax
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%rax
jne    122d <set_state+0xbd>
lea    0xdd8(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
lea    0xdc7(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%rdx
mov    0x2d8c(%rip),%rax
mov    (%rax),%rcx
lea    0xdd4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<set_state>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x10,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
mov    0x2e2c(%rip),%r15
cmp    (%r15),%rax
jl     11e0 <set_state+0x70>
test   %r14,%r14
je     11e0 <set_state+0x70>
mov    0x2e2b(%rip),%rax
cmp    (%rax),%rbx
jg     11e0 <set_state+0x70>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e0 <set_state+0x70>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df9(%rip),%rax
cmp    (%rax),%rbx
je     11f8 <set_state+0x88>
mov    0x2dcd(%rip),%rax
cmp    (%rax),%rbx
jne    1204 <set_state+0x94>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dbd(%rip),%rbx
mov    (%rbx),%esi
lea    0xdf0(%rip),%rdi
call   1030 <fputs@plt>
mov    (%rbx),%edi
mov    (%r15),%rdx
mov    0x2dc3(%rip),%rax
mov    (%rax),%rcx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [4 x i8] c"Bla\00"
@.str.1 = [54 x i8] c"Invalid input for state. It must be a number between \00"
@stderr = global i32 0
@.str.2 = [11 x i8] c"%d and %d\0A\00"
define i32 @set_state(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = call i8* @calloc(i32 16, i32 1)
store i8* %5, i8** %3
%6 = load i8*, i8** %2
%7 = call i64 @strtol(i8* %6, i8** %3, i32 10)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = load i64, i64* @INT_MIN
%10 = icmp sge i64 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %1
%12 = load i64, i64* %4
%13 = load i64, i64* @INT_MAX
%14 = icmp sle i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i64, i64* %4
%25 = trunc i64 %24 to i32
ret i32 %25
26: ; preds = %18, %15, %11, %1
%27 = load i64, i64* %4
%28 = load i64, i64* @LONG_MIN
%29 = icmp eq i64 %27, %28
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i64, i64* %4
%32 = load i64, i64* @LONG_MAX
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30, %26
%35 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
%37 = load i32, i32* @stderr
%38 = call i32 @fputs(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @stderr
%40 = load i64, i64* @INT_MIN
%41 = load i64, i64* @INT_MAX
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %40, i64 %41)
%43 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@INT_MIN = global i64 0
@INT_MAX = global i64 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [4 x i8] c"Bla\00"
@.str.1 = [54 x i8] c"Invalid input for state. It must be a number between \00"
@stderr = global i32 0
@.str.2 = [11 x i8] c"%d and %d\0A\00"
define i32 @set_state(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call dereferenceable_or_null(16) i8* @calloc(i32 16, i32 1)
store i8* %4, i8** %2
%5 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%6 = load i64, i64* @INT_MIN
%7 = icmp slt i64 %5, %6
br i1 %7, label %19, label %8
8: ; preds = %1
%9 = load i64, i64* @INT_MAX
%10 = icmp sle i64 %5, %9
%11 = icmp ne i8* %0, null
%12 = and i1 %11, %10
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = tail call i64 @strcmp(i8* %0, i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = trunc i64 %5 to i32
ret i32 %18
19: ; preds = %13, %8, %1
%20 = load i64, i64* @LONG_MIN
%21 = icmp eq i64 %5, %20
%22 = load i64, i64* @LONG_MAX
%23 = icmp eq i64 %5, %22
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %19, %25
%28 = load i32, i32* @stderr
%29 = tail call i32 @fputs(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @stderr
%31 = load i64, i64* @INT_MIN
%32 = load i64, i64* @INT_MAX
%33 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %31, i64 %32)
%34 = tail call i32 @exit(i32 -1)
unreachable
}