#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 /*<<< orphan*/ assert(int);
int atoi_safe(char *);
int /*<<< orphan*/ printf(char *, int);
void check_atoi_safe() {
  char buffer[2] = "5";
  buffer[1] = '\0';
  int a = 5;
  int b = atoi_safe(buffer);
  printf("%d\n", b);
  assert(a == b);
  char buffer2[3] = "-5\0";
  buffer[1] = '\0';
  int a2 = -5;
  int b2 = atoi_safe(buffer2);
  printf("%d", b2);
  assert(a2 == b2);
}


x86 assembly (clang, -O0):
<check_atoi_safe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec6(%rip),%ax
mov    %ax,-0x2(%rbp)
movb   $0x0,-0x1(%rbp)
movl   $0x5,-0x8(%rbp)
lea    -0x2(%rbp),%rdi
call   1050 <atoi_safe@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0xe81(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xe79(%rip),%al
mov    %al,-0xd(%rbp)
movb   $0x0,-0x1(%rbp)
movl   $0xfffffffb,-0x14(%rbp)
lea    -0xf(%rbp),%rdi
call   1050 <atoi_safe@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_atoi_safe>:
push   %rbx
sub    $0x10,%rsp
movw   $0x35,0xa(%rsp)
lea    0xa(%rsp),%rdi
call   1050 <atoi_safe@plt>
mov    %eax,%ebx
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
cmp    $0x5,%ebx
sete   %dil
call   1040 <assert@plt>
movb   $0x0,0xe(%rsp)
movw   $0x352d,0xc(%rsp)
movb   $0x0,0xb(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <atoi_safe@plt>
mov    %eax,%ebx
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
cmp    $0xfffffffb,%ebx
sete   %dil
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.check_atoi_safe.buffer = [2 x i8] c"5\00"
@.str = [4 x i8] c"%d\0A\00"
@__const.check_atoi_safe.buffer2 = [3 x i8] c"-5\00"
@.str.1 = [3 x i8] c"%d\00"
define void @check_atoi_safe() {
%1 = alloca [2 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [2 x i8]* %1 to i8*
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
store i8 0, i8* %8
store i32 5, i32* %2
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%10 = call i32 @atoi_safe(i8* %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp eq i32 %13, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = bitcast [3 x i8]* %4 to i8*
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
store i8 0, i8* %19
store i32 -5, i32* %5
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%21 = call i32 @atoi_safe(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp eq i32 %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@__const.check_atoi_safe.buffer2 = [3 x i8] c"-5\00"
@.str.1 = [3 x i8] c"%d\00"
define void @check_atoi_safe() {
%1 = alloca i16
%2 = bitcast i16* %1 to [2 x i8]*
%3 = alloca [3 x i8]
%4 = bitcast i16* %1 to i8*
store i16 53, i16* %1
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
%6 = call i32 @atoi_safe(i8* %4)
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %6, 5
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 0, i8* %5
%12 = call i32 @atoi_safe(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %12, -5
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
ret void
}