#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;
scalar_t__ errno;
int /*<<< orphan*/ isdigit(char *);
int /*<<< orphan*/ log_message(char *, char *);
int strtol(char *, char **, int);
int parseint(char *string, bool unsignedint, int fallback) {
  errno = 0;
  char *end = string;
  int result = strtol(string, &end, 10);
  if (errno == ERANGE) {
    log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                "Configuration parameter 'buff_size' is to large  (overflow), "
                "falling back to default\r\n");
    return fallback;
  }
  if (unsignedint) {
    if ((!isdigit(string) || *string == '+') || *end) {
      log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                  "Configuration parameter 'buff_size' is not a valid integer, "
                  "falling back to default\r\n");
      return fallback;
    }
  } else {
    if (*end) {
      log_message("[WARNING][%d-%d-%d %d:%d:%d] ",
                  "Configuration parameter 'buff_size' is not a valid integer, "
                  "falling back to default\r\n");
      return fallback;
    }
  }
  return 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    0x2e8f(%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   1040 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    11a5 <parseint+0x75>
lea    0xe72(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1050 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parseint+0x10a>
cmpl   $0x0,-0x14(%rbp)
je     1204 <parseint+0xd4>
mov    -0x10(%rbp),%rdi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     11e1 <parseint+0xb1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     11e1 <parseint+0xb1>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ff <parseint+0xcf>
lea    0xe18(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1050 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parseint+0x10a>
jmp    1234 <parseint+0x104>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     122f <parseint+0xff>
lea    0xde8(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1050 <log_message@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <parseint+0x10a>
jmp    1234 <parseint+0x104>
mov    -0x24(%rbp),%eax
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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2e8c(%rip),%r12
movq   $0x0,(%r12)
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ebp
mov    (%r12),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    119f <parseint+0x6f>
lea    0xe9d(%rip),%rsi
lea    0xe78(%rip),%rdi
call   1050 <log_message@plt>
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15d,%r15d
je     11c8 <parseint+0x98>
mov    %rbx,%rdi
call   1030 <isdigit@plt>
lea    0xec2(%rip),%rsi
test   %eax,%eax
je     1181 <parseint+0x51>
cmpb   $0x2b,(%rbx)
je     1181 <parseint+0x51>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1181 <parseint+0x51>
jmp    1190 <parseint+0x60>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1190 <parseint+0x60>
lea    0xe9c(%rip),%rsi
jmp    1181 <parseint+0x51>

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 = [87 x i8] c"Configuration parameter 'buff_size' is to large (overflow), falling back to default\0D\0A\00"
@.str.2 = [86 x i8] c"Configuration parameter 'buff_size' is not a valid integer, falling back to default\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 i32
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 i32 @strtol(i8* %11, i8** %8, i32 10)
store i32 %12, i32* %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 ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %7
store i32 %18, i32* %4
br label %50
19: ; preds = %3
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = call i32 @isdigit(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i8*, i8** %8
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31, %26, %22
%37 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %7
store i32 %38, i32* %4
br label %50
39: ; preds = %31
br label %48
40: ; preds = %19
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %7
store i32 %46, i32* %4
br label %50
47: ; preds = %40
br label %48
48: ; preds = %47, %39
%49 = load i32, i32* %9
store i32 %49, i32* %4
br label %50
50: ; preds = %48, %44, %36, %16
%51 = load i32, i32* %4
ret i32 %51
}

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 = [87 x i8] c"Configuration parameter 'buff_size' is to large (overflow), falling back to default\0D\0A\00"
@.str.2 = [86 x i8] c"Configuration parameter 'buff_size' is not a valid integer, falling back to default\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 i32 @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 %26, label %10
10: ; preds = %3
%11 = icmp eq i32 %1, 0
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = tail call i32 @isdigit(i8* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 43
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %29, label %26
22: ; preds = %10
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %22, %12, %15, %18, %3
%27 = phi i8* [ getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), %22 ]
%28 = tail call i32 @log_message(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %18, %22
%30 = phi i32 [ %6, %22 ], [ %6, %18 ], [ %2, %26 ]
ret i32 %30
}