#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 *);
int rand();
int main() {
  int i = rand();
  if (i == 0) {
    printf("NULL\n");
    goto err;
  }
restart:
  i = 5;
  while (i < 100) {
    printf("1\n");
    printf("2\n");
    int j = 0;
    while (j < 50) {
      printf("3\n");
      int tmp = rand();
      if (tmp == 1) {
        printf("restart!\n");
        goto restart;
      }
      if (tmp == 2) {
        printf("stop\n");
        goto err;
      }
      j++;
    }
    i++;
  }
  printf("4\n");
  printf("5\n");
  return 0;
err:
  printf("err exit\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1154 <main+0x34>
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
jmp    121f <main+0xff>
jmp    1159 <main+0x39>
movl   $0x5,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    11fb <main+0xdb>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x32,-0xc(%rbp)
jge    11ed <main+0xcd>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    11c4 <main+0xa4>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    1159 <main+0x39>
cmpl   $0x2,-0x10(%rbp)
jne    11df <main+0xbf>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    121f <main+0xff>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <main+0x69>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <main+0x40>
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <main+0x112>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <rand@plt>
mov    $0x1,%ebx
lea    0xeca(%rip),%rbp
test   %eax,%eax
je     11ef <main+0xcf>
mov    $0x5,%r15d
lea    0xeb1(%rip),%rdi
lea    0xeac(%rip),%rbp
lea    0xeb0(%rip),%rbx
mov    %rdi,%r14
call   1030 <puts@plt>
mov    %rbp,%r13
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    $0x32,%r12d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <rand@plt>
cmp    $0x1,%eax
je     11c0 <main+0xa0>
cmp    $0x2,%eax
je     11da <main+0xba>
add    $0xffffffff,%r12d
jne    1180 <main+0x60>
lea    0x1(%r15),%eax
cmp    $0x63,%r15d
mov    %eax,%r15d
mov    %r14,%rdi
mov    %r13,%rbp
jb     1161 <main+0x41>
jmp    1214 <main+0xf4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%r15d
mov    %r14,%rdi
mov    %r13,%rbp
jmp    1161 <main+0x41>
lea    0xe32(%rip),%rdi
mov    $0x1,%ebx
lea    0xe1b(%rip),%rbp
jmp    11f6 <main+0xd6>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
lea    0xde5(%rip),%rbp
lea    0xddc(%rip),%rdi
jmp    11f6 <main+0xd6>

LLVM IR (-O0):
@.str = [6 x i8] c"NULL\0A\00"
@.str.1 = [3 x i8] c"1\0A\00"
@.str.2 = [3 x i8] c"2\0A\00"
@.str.3 = [3 x i8] c"3\0A\00"
@.str.4 = [10 x i8] c"restart!\0A\00"
@.str.5 = [6 x i8] c"stop\0A\00"
@.str.6 = [3 x i8] c"4\0A\00"
@.str.7 = [3 x i8] c"5\0A\00"
@.str.8 = [10 x i8] c"err exit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @rand()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %42
10: ; preds = %0
br label %11
11: ; preds = %26, %10
store i32 5, i32* %2
br label %12
12: ; preds = %36, %11
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 100
br i1 %14, label %15, label %39
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %18
18: ; preds = %33, %15
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 50
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (...) @rand()
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %11
28: ; preds = %21
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %42
33: ; preds = %28
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %18
36: ; preds = %18
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %12
39: ; preds = %12
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %44
42: ; preds = %31, %8
%43 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %1
br label %44
44: ; preds = %42, %39
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@str = [2 x i8] c"4\00"
@str.9 = [2 x i8] c"5\00"
@str.10 = [2 x i8] c"1\00"
@str.11 = [2 x i8] c"2\00"
@str.12 = [9 x i8] c"err exit\00"
@str.13 = [2 x i8] c"3\00"
@str.14 = [5 x i8] c"stop\00"
@str.15 = [9 x i8] c"restart!\00"
@str.16 = [5 x i8] c"NULL\00"
define i32 @main() {
%1 = tail call i32 (...) @rand()
%2 = icmp eq i32 %1, 0
br i1 %2, label %21, label %5
3: ; preds = %9
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.15, i64 0, i64 0))
br label %19
5: ; preds = %0, %19
%6 = phi i32 [ %20, %19 ], [ 5, %0 ]
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
br label %9
9: ; preds = %5, %13
%10 = phi i32 [ 0, %5 ], [ %14, %13 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 (...) @rand()
switch i32 %12, label %13 [
i32 1, label %3
i32 2, label %21
]
13: ; preds = %9
%14 = add nuw nsw i32 %10, 1
%15 = icmp eq i32 %14, 50
br i1 %15, label %16, label %9
16: ; preds = %13
%17 = add nuw nsw i32 %6, 1
%18 = icmp ult i32 %6, 99
br i1 %18, label %19, label %21
19: ; preds = %16, %3
%20 = phi i32 [ %17, %16 ], [ 5, %3 ]
br label %5
21: ; preds = %16, %9, %0
%22 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.16, i64 0, i64 0), %0 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.14, i64 0, i64 0), %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %16 ]
%23 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.12, i64 0, i64 0), %0 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.12, i64 0, i64 0), %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0), %16 ]
%24 = phi i32 [ 1, %0 ], [ 1, %9 ], [ 0, %16 ]
%25 = tail call i32 @puts(i8* dereferenceable(1) %22)
%26 = tail call i32 @puts(i8* dereferenceable(1) %23)
ret i32 %24
}