#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*/ f_broken(int *);
int /*<<< orphan*/ f_working(int **);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int *);
int main() {
  int *a = malloc(3 * sizeof(int));
  printf("a before f_broken: %lu\n", a);
  f_broken(a);
  printf("a after f_broken: %lu\n", a);
  printf("a before f_working %lu\n", a);
  f_working(&a);
  printf("a after f_working: %lu\n", a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <f_broken@plt>
mov    -0x10(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1060 <f_working@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
lea    0xea2(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <f_broken@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
call   1060 <f_working@plt>
mov    0x8(%rsp),%rsi
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"a before f_broken: %lu\0A\00"
@.str.1 = [23 x i8] c"a after f_broken: %lu\0A\00"
@.str.2 = [24 x i8] c"a before f_working %lu\0A\00"
@.str.3 = [24 x i8] c"a after f_working: %lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @malloc(i32 12)
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %4)
%6 = load i32*, i32** %2
%7 = call i32 @f_broken(i32* %6)
%8 = load i32*, i32** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = load i32*, i32** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %10)
%12 = call i32 @f_working(i32** %2)
%13 = load i32*, i32** %2
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"a before f_broken: %lu\0A\00"
@.str.1 = [23 x i8] c"a after f_broken: %lu\0A\00"
@.str.2 = [24 x i8] c"a before f_working %lu\0A\00"
@.str.3 = [24 x i8] c"a after f_working: %lu\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
%3 = tail call i32* @malloc(i32 12)
store i32* %3, i32** %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = tail call i32 @f_broken(i32* %3)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%8 = call i32 @f_working(i32** %1)
%9 = load i32*, i32** %1
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %9)
ret i32 0
}