#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 */
int mutt_atol(char const *, long *);
int mutt_atoi(const char *str, int *dst) {
  int rc;
  long res;
  int tmp;
  int *t = dst ? dst : &tmp;
  *t = 0;
  if ((rc = mutt_atol(str, &res)) < 0)
    return rc;
  if ((int)res != res)
    return -2;
  *t = (int)res;
  return 0;
}


x86 assembly (clang, -O0):
<mutt_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1138 <mutt_atoi+0x28>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1145 <mutt_atoi+0x35>
lea    -0x2c(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1145 <mutt_atoi+0x35>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <mutt_atol@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    117b <mutt_atoi+0x6b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <mutt_atoi+0x9a>
mov    -0x28(%rbp),%rax
cltq
cmp    -0x28(%rbp),%rax
je     1197 <mutt_atoi+0x87>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11aa <mutt_atoi+0x9a>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mutt_atoi>:
push   %rbx
sub    $0x10,%rsp
test   %rsi,%rsi
lea    0xc(%rsp),%rbx
cmovne %rsi,%rbx
movl   $0x0,(%rbx)
mov    %rsp,%rsi
call   1030 <mutt_atol@plt>
test   %eax,%eax
js     1148 <mutt_atoi+0x38>
mov    (%rsp),%rcx
movslq %ecx,%rdx
mov    $0xfffffffe,%eax
cmp    %rcx,%rdx
jne    1148 <mutt_atoi+0x38>
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @mutt_atoi(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** %5
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %12
%16 = phi i32* [ %13, %12 ], [ %8, %14 ]
store i32* %16, i32** %9
%17 = load i32*, i32** %9
store i32 0, i32* %17
%18 = load i8*, i8** %4
%19 = call i32 @mutt_atol(i8* %18, i64* %7)
store i32 %19, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %34
23: ; preds = %15
%24 = load i64, i64* %7
%25 = trunc i64 %24 to i32
%26 = sext i32 %25 to i64
%27 = load i64, i64* %7
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -2, i32* %3
br label %34
30: ; preds = %23
%31 = load i64, i64* %7
%32 = trunc i64 %31 to i32
%33 = load i32*, i32** %9
store i32 %32, i32* %33
store i32 0, i32* %3
br label %34
34: ; preds = %30, %29, %21
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @mutt_atoi(i8* %0, i32* writeonly %1) {
%3 = alloca i64
%4 = alloca i32
%5 = bitcast i64* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32* %1, null
%8 = select i1 %7, i32* %4, i32* %1
store i32 0, i32* %8
%9 = call i32 @mutt_atol(i8* %0, i64* %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i64, i64* %3
%13 = add i64 %12, 2147483648
%14 = icmp ult i64 %13, 4294967296
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = trunc i64 %12 to i32
store i32 %16, i32* %8
br label %17
17: ; preds = %11, %2, %15
%18 = phi i32 [ 0, %15 ], [ %9, %2 ], [ -2, %11 ]
ret i32 %18
}