#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*/ printf(char *, char);
int run(char i) {
  if (i > 0) {
    int *p = (int *)0;
    int v = *p;
    printf("Null pointer: %d\n", v);
    return 0;
  } else {
    printf("i is %d\n", i);
    return run(i + 1);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jle    116a <run+0x4a>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xeaa(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    118c <run+0x6c>
lea    0xea1(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1040 <printf@plt>
movsbl -0x5(%rbp),%eax
add    $0x1,%eax
movsbl %al,%edi
call   1030 <run@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   %bl,%bl
jg     1145 <run+0x35>
lea    0xef1(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %bl,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%bl
cmp    $0x1,%bl
jne    1130 <run+0x20>
lea    0xeb4(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Null pointer: %d\0A\00"
@.str.1 = [9 x i8] c"i is %d\0A\00"
define i32 @run(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32
store i8 %0, i8* %3
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
store i32* null, i32** %4
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = trunc i32 %12 to i8
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext %13)
store i32 0, i32* %2
br label %23
15: ; preds = %1
%16 = load i8, i8* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %16)
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = add nsw i32 %19, 1
%21 = trunc i32 %20 to i8
%22 = call i32 @run(i8 signext %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %15, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [18 x i8] c"Null pointer: %d\0A\00"
@.str.1 = [9 x i8] c"i is %d\0A\00"
define i32 @run(i8 signext %0) {
%2 = icmp sgt i8 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %5, %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8 signext undef)
ret i32 0
5: ; preds = %1, %5
%6 = phi i8 [ %8, %5 ], [ %0, %1 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %6)
%8 = add i8 %6, 1
%9 = icmp eq i8 %6, 0
br i1 %9, label %3, label %5
}