#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);
int f1(int val) {
  int num = 0;
  int *ptr = &num;
  printf("%lu\n", (unsigned long)&val);
  if (val == 0) {
    int val;
    printf("%lu\n", (unsigned long)&val);
    val = 5;
    ptr = &val;
  }
  printf("*ptr = [%d]\n", *ptr);
  return (*ptr + 1);
}


x86 assembly (clang, -O0):
<f1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x4(%rbp),%rax
mov    %eax,%esi
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1167 <f1+0x57>
lea    -0x14(%rbp),%rax
mov    %eax,%esi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x14(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f1>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0x4(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x4(%rsp),%rsi
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,0x4(%rsp)
je     1142 <f1+0x32>
lea    0xc(%rsp),%rbx
xor    %esi,%esi
jmp    1159 <f1+0x49>
lea    0x8(%rsp),%rbx
lea    0xeb2(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%eax
add    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\0A\00"
@.str.1 = [13 x i8] c"*ptr = [%d]\0A\00"
define i32 @f1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = ptrtoint i32* %2 to i64
%7 = trunc i64 %6 to i32
%8 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = bitcast i32* %4 to i8*
%13 = ptrtoint i32* %4 to i64
%14 = trunc i64 %13 to i32
%15 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
br label %17
17: ; preds = %11, %1
%18 = phi i32 [ %16, %11 ], [ 0, %1 ]
%19 = phi i32* [ %4, %11 ], [ %3, %1 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%21 = load i32, i32* %19
%22 = add nsw i32 %21, 1
ret i32 %22
}