#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 */
typedef int u_int32_t;

/* Variables and functions */
int arc4random();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, const char *argv[]) {
  int *null_ptr = 0;
  printf("Hello, fault!\n");
  u_int32_t val = (arc4random() & 0x0f);
  printf("val=%u\n", val);
  if (val == 0x07)
    printf("Now segfault %d\n", *null_ptr);
  else
    printf("Better luck next time!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <arc4random@plt>
and    $0xf,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x7,-0x1c(%rbp)
jne    118d <main+0x6d>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119b <main+0x7b>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <arc4random@plt>
mov    %eax,%ebx
and    $0xf,%ebx
lea    0xeb0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x7,%ebx
jne    116e <main+0x3e>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    117a <main+0x4a>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Hello, fault!\0A\00"
@.str.1 = [8 x i8] c"val=%u\0A\00"
@.str.2 = [17 x i8] c"Now segfault %d\0A\00"
@.str.3 = [24 x i8] c"Better luck next time!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @arc4random()
%10 = and i32 %9, 15
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 7
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"val=%u\0A\00"
@.str.2 = [17 x i8] c"Now segfault %d\0A\00"
@str = [14 x i8] c"Hello, fault!\00"
@str.4 = [23 x i8] c"Better luck next time!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @arc4random()
%5 = and i32 %4, 15
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %5, 7
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 undef)
br label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
ret i32 0
}