#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 atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
void print_atoi(char *s) {
  int scanned_value;
  printf("%10s  %4d  [", s == NULL ? "NULL" : s, atoi(s));
  if (sscanf(s, "%d", &scanned_value) != 1) {
    printf("fail");
  } else {
    printf("%d", scanned_value);
  }
  printf("]\n");
}


x86 assembly (clang, -O0):
<print_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1157 <print_atoi+0x27>
lea    0xebf(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    115f <print_atoi+0x2f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11b4 <print_atoi+0x84>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <print_atoi+0x95>
mov    -0xc(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_atoi>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xebc(%rip),%rbx
cmovne %rdi,%rbx
call   1060 <atoi@plt>
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9e(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    119a <print_atoi+0x5a>
mov    0x4(%rsp),%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a8 <print_atoi+0x68>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%10s %4d [\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"fail\00"
@.str.4 = [3 x i8] c"]\0A\00"
define void @print_atoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
br label %9
7: ; preds = %1
%8 = load i8*, i8** %2
br label %9
9: ; preds = %7, %6
%10 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %6 ], [ %8, %7 ]
%11 = load i8*, i8** %2
%12 = call i32 @atoi(i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %12)
%14 = load i8*, i8** %2
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %22
19: ; preds = %9
%20 = load i32, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%10s %4d [\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"fail\00"
@str = [2 x i8] c"]\00"
define void @print_atoi(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0
%6 = tail call i32 @atoi(i8* %0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %6)
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %12, %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}