#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;
long UINT_MAX;
scalar_t__ errno;
int /*<<< orphan*/ log_message(char *, char *);
long strtol(char *, char **, int);
int parseint(char *string, bool unsignedint, int fallback) {
  errno = 0;
  char *end = string;
  long result = strtol(string, &end, 10);
  if (errno == ERANGE) {
    log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                "Configuration parameter is to large  (overflow), falling back "
                "to default\r\n");
    return fallback;
  }
  if (unsignedint) {
    if (result > UINT_MAX || result < 0) {
      log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                  "Parsed string is not within unsigned integer range\r\n");
      return fallback;
    }
  } else {
    if (result > INT_MAX || result < INT_MIN) {
      log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                  "Parsed string is not within signed integer range\r\n");
      return fallback;
    }
  }
  if (end == string) {
    log_message("[WARNING][%d-%d-%d %d:%d:%d] ", "String is not numeric\r\n");
    return fallback;
  }
  if ('\0' != *end) {
    log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                "parseint got extra characters on input line\r\n");
    return fallback;
  }
  return (int)result;
}


x86 assembly (clang, -O0):
<parseint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e87(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <parseint+0x76>
lea    0xe81(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1040 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <parseint+0x16f>
cmpl   $0x0,-0x14(%rbp)
je     11e2 <parseint+0xc2>
mov    -0x28(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jg     11bf <parseint+0x9f>
cmpq   $0x0,-0x28(%rbp)
jge    11dd <parseint+0xbd>
lea    0xe3a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <parseint+0x16f>
jmp    122d <parseint+0x10d>
mov    -0x28(%rbp),%rax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
jg     120a <parseint+0xea>
mov    -0x28(%rbp),%rax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%rax
jge    1228 <parseint+0x108>
lea    0xdef(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1040 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <parseint+0x16f>
jmp    122d <parseint+0x10d>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1259 <parseint+0x139>
lea    0xdbe(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1040 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <parseint+0x16f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1288 <parseint+0x168>
lea    0xd8f(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1040 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <parseint+0x16f>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2e89(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rdi,(%rsp)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x0(%rbp),%rcx
mov    0x2e75(%rip),%rdx
cmp    (%rdx),%rcx
jne    1178 <parseint+0x58>
lea    0xe99(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <log_message@plt>
jmp    120b <parseint+0xeb>
test   %r15d,%r15d
je     11a3 <parseint+0x83>
test   %rax,%rax
js     118e <parseint+0x6e>
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
jle    11bb <parseint+0x9b>
lea    0xe6b(%rip),%rdi
lea    0xecd(%rip),%rsi
call   1040 <log_message@plt>
jmp    120b <parseint+0xeb>
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jg     11de <parseint+0xbe>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
jl     11de <parseint+0xbe>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     11f3 <parseint+0xd3>
cmpb   $0x0,(%rcx)
je     1208 <parseint+0xe8>
lea    0xe30(%rip),%rdi
lea    0xf12(%rip),%rsi
call   1040 <log_message@plt>
jmp    120b <parseint+0xeb>
lea    0xe1b(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <log_message@plt>
jmp    120b <parseint+0xeb>
lea    0xe06(%rip),%rdi
lea    0xed0(%rip),%rsi
call   1040 <log_message@plt>
jmp    120b <parseint+0xeb>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [30 x i8] c"[WARNING][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [75 x i8] c"Configuration parameter is to large (overflow), falling back to default\0D\0A\00"
@UINT_MAX = global i64 0
@.str.2 = [53 x i8] c"Parsed string is not within unsigned integer range\0D\0A\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.3 = [51 x i8] c"Parsed string is not within signed integer range\0D\0A\00"
@.str.4 = [24 x i8] c"String is not numeric\0D\0A\00"
@.str.5 = [46 x i8] c"parseint got extra characters on input line\0D\0A\00"
define i32 @parseint(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 0, i64* @errno
%10 = load i8*, i8** %5
store i8* %10, i8** %8
%11 = load i8*, i8** %5
%12 = call i64 @strtol(i8* %11, i8** %8, i32 10)
store i64 %12, i64* %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %7
store i32 %18, i32* %4
br label %63
19: ; preds = %3
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i64, i64* %9
%24 = load i64, i64* @UINT_MAX
%25 = icmp sgt i64 %23, %24
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i64, i64* %9
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26, %22
%30 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %7
store i32 %31, i32* %4
br label %63
32: ; preds = %26
br label %45
33: ; preds = %19
%34 = load i64, i64* %9
%35 = load i64, i64* @INT_MAX
%36 = icmp sgt i64 %34, %35
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i64, i64* %9
%39 = load i64, i64* @INT_MIN
%40 = icmp slt i64 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %37, %33
%42 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %7
store i32 %43, i32* %4
br label %63
44: ; preds = %37
br label %45
45: ; preds = %44, %32
%46 = load i8*, i8** %8
%47 = load i8*, i8** %5
%48 = icmp eq i8* %46, %47
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* %7
store i32 %51, i32* %4
br label %63
52: ; preds = %45
%53 = load i8*, i8** %8
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 0, %55
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
%59 = load i32, i32* %7
store i32 %59, i32* %4
br label %63
60: ; preds = %52
%61 = load i64, i64* %9
%62 = trunc i64 %61 to i32
store i32 %62, i32* %4
br label %63
63: ; preds = %60, %57, %49, %41, %29, %16
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [30 x i8] c"[WARNING][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [75 x i8] c"Configuration parameter is to large (overflow), falling back to default\0D\0A\00"
@UINT_MAX = global i64 0
@.str.2 = [53 x i8] c"Parsed string is not within unsigned integer range\0D\0A\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.3 = [51 x i8] c"Parsed string is not within signed integer range\0D\0A\00"
@.str.4 = [24 x i8] c"String is not numeric\0D\0A\00"
@.str.5 = [46 x i8] c"parseint got extra characters on input line\0D\0A\00"
define i32 @parseint(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
store i64 0, i64* @errno
%5 = bitcast i8** %4 to i8*
store i8* %0, i8** %4
%6 = call i64 @strtol(i8* %0, i8** %4, i32 10)
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
br label %41
12: ; preds = %3
%13 = icmp eq i32 %1, 0
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = load i64, i64* @UINT_MAX
%16 = icmp sgt i64 %6, %15
%17 = icmp slt i64 %6, 0
%18 = or i1 %17, %16
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %41
21: ; preds = %12
%22 = load i64, i64* @INT_MAX
%23 = icmp sgt i64 %6, %22
%24 = load i64, i64* @INT_MIN
%25 = icmp slt i64 %6, %24
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %41
29: ; preds = %21, %14
%30 = load i8*, i8** %4
%31 = icmp eq i8* %30, %0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %41
34: ; preds = %29
%35 = load i8, i8* %30
%36 = icmp eq i8 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0))
br label %41
39: ; preds = %34
%40 = trunc i64 %6 to i32
br label %41
41: ; preds = %39, %37, %32, %27, %19, %10
%42 = phi i32 [ %2, %10 ], [ %2, %19 ], [ %2, %32 ], [ %2, %37 ], [ %40, %39 ], [ %2, %27 ]
ret i32 %42
}