#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 *);
scalar_t__ sub_fun(int);
int fun(char x) {
  if (sub_fun(0)) {
    printf("hej\n");
  }
  if (0)
    printf("NO");
  else if (sub_fun(0)) {
    printf("hej 2\n");
  }
  if (sub_fun(10)) {
    printf("hej 3\n");
  } else {
    printf("HEJ\n");
  }
  while (sub_fun(9)) {
    printf("hoo\n");
  }
  do {
    printf("haa\n");
  } while (sub_fun(9));
  return x;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
xor    %edi,%edi
call   1030 <sub_fun@plt>
cmp    $0x0,%rax
je     114b <fun+0x2b>
lea    0xeba(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1030 <sub_fun@plt>
cmp    $0x0,%rax
je     1168 <fun+0x48>
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <sub_fun@plt>
cmp    $0x0,%rax
je     118d <fun+0x6d>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
jmp    1199 <fun+0x79>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
jmp    119e <fun+0x7e>
mov    $0x9,%edi
call   1030 <sub_fun@plt>
cmp    $0x0,%rax
je     11c3 <fun+0xa3>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    119e <fun+0x7e>
jmp    11c8 <fun+0xa8>
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x9,%edi
call   1030 <sub_fun@plt>
cmp    $0x0,%rax
jne    11c8 <fun+0xa8>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
je     113d <fun+0x1d>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
je     1155 <fun+0x35>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
lea    0xe97(%rip),%rax
lea    0xe9c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    $0x9,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
je     11a7 <fun+0x87>
lea    0xe79(%rip),%rbx
nop
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x9,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
jne    1190 <fun+0x70>
lea    0xe56(%rip),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x9,%edi
call   1040 <sub_fun@plt>
test   %rax,%rax
jne    11b0 <fun+0x90>
movsbl %bpl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"hej\0A\00"
@.str.1 = [7 x i8] c"hej 2\0A\00"
@.str.2 = [7 x i8] c"hej 3\0A\00"
@.str.3 = [5 x i8] c"HEJ\0A\00"
@.str.4 = [5 x i8] c"hoo\0A\00"
@.str.5 = [5 x i8] c"haa\0A\00"
define i32 @fun(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = call i64 @sub_fun(i32 0)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = call i64 @sub_fun(i32 0)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i64 @sub_fun(i32 10)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
br label %20
20: ; preds = %23, %19
%21 = call i64 @sub_fun(i32 9)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %20
25: ; preds = %20
br label %26
26: ; preds = %28, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26
%29 = call i64 @sub_fun(i32 9)
%30 = icmp ne i64 %29, 0
br i1 %30, label %26, label %31
31: ; preds = %28
%32 = load i8, i8* %2
%33 = sext i8 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@str = [4 x i8] c"HEJ\00"
@str.6 = [4 x i8] c"haa\00"
@str.7 = [4 x i8] c"hoo\00"
@str.8 = [6 x i8] c"hej 3\00"
@str.9 = [6 x i8] c"hej 2\00"
@str.10 = [4 x i8] c"hej\00"
define i32 @fun(i8 signext %0) {
%2 = tail call i64 @sub_fun(i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.10, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i64 @sub_fun(i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i64 @sub_fun(i32 10)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
%16 = tail call i64 @sub_fun(i32 9)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %11, %18
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.7, i64 0, i64 0))
%20 = tail call i64 @sub_fun(i32 9)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %18
22: ; preds = %18, %11
br label %23
23: ; preds = %22, %23
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.6, i64 0, i64 0))
%25 = tail call i64 @sub_fun(i32 9)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %23
27: ; preds = %23
%28 = sext i8 %0 to i32
ret i32 %28
}