#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 atoi(char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int *p_global = malloc(4);
  *p_global = 100;
  int *p_local = malloc(4);
  int *p_ptr_to_global = p_global;
  p_global = p_local;
  if (atoi(argv[1]) > 10) {
    printf("something\n");
  } else {
    p_global = p_ptr_to_global;
  }
  free(p_local);
  int use_after_free = *p_global;
  printf("Hi mom: %d\n", use_after_free);
  free(p_global);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x64,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
cmp    $0xa,%eax
jle    11b5 <main+0x75>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bd <main+0x7d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x64,(%rax)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
cmp    $0xb,%eax
jl     1195 <main+0x45>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rbx),%esi
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"something\0A\00"
@.str.1 = [12 x i8] c"Hi mom: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @malloc(i32 4)
store i32* %10, i32** %6
%11 = load i32*, i32** %6
store i32 100, i32* %11
%12 = call i32* @malloc(i32 4)
store i32* %12, i32** %7
%13 = load i32*, i32** %6
store i32* %13, i32** %8
%14 = load i32*, i32** %7
store i32* %14, i32** %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
%19 = icmp sgt i32 %18, 10
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %24
22: ; preds = %2
%23 = load i32*, i32** %8
store i32* %23, i32** %6
br label %24
24: ; preds = %22, %20
%25 = load i32*, i32** %7
%26 = call i32 @free(i32* %25)
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @free(i32* %31)
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Hi mom: %d\0A\00"
@str = [10 x i8] c"something\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @malloc(i32 4)
store i32 100, i32* %3
%4 = tail call i32* @malloc(i32 4)
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp sgt i32 %7, 10
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %2, %9
%12 = phi i32* [ %4, %9 ], [ %3, %2 ]
%13 = tail call i32 @free(i32* %4)
%14 = load i32, i32* %12
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = tail call i32 @free(i32* %12)
ret i32 0
}