#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*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void fun(int level) {
  void *my_mem = malloc(1000);
  if (0) {
    printf("FREE AT LEVEL %d\n", level);
    free(my_mem);
  }
  if (0) {
    printf("I got destroyed or returned %d\n", level);
  }
  printf("LEVEL %d\n", level);
  if (level == 10) {
    ;
    printf("SHOULD NOT BE PRINTED 1\n");
    return;
  } else {
    fun(level + 1);
    printf("SHOULD NOT BE PRINTED 2\n");
  }
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xa,-0x4(%rbp)
jne    1177 <fun+0x47>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1190 <fun+0x60>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1030 <fun@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbx
mov    %edi,%ebx
lea    0xec6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xa,%ebx
jne    1155 <fun+0x25>
lea    0xed3(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <fun@plt>
lea    0xea4(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"LEVEL %d\0A\00"
@.str.1 = [25 x i8] c"SHOULD NOT BE PRINTED 1\0A\00"
@.str.2 = [25 x i8] c"SHOULD NOT BE PRINTED 2\0A\00"
define void @fun(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @malloc(i32 1000)
store i8* %4, i8** %3
%5 = load i32, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 10
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %15
11: ; preds = %1
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %9, %11
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"LEVEL %d\0A\00"
@str = [24 x i8] c"SHOULD NOT BE PRINTED 2\00"
@str.3 = [24 x i8] c"SHOULD NOT BE PRINTED 1\00"
define void @fun(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp eq i32 %0, 10
br i1 %3, label %4, label %7
4: ; preds = %1, %7
%5 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0), %1 ]
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
ret void
7: ; preds = %1
%8 = add nsw i32 %0, 1
tail call void @fun(i32 %8)
br label %4
}