#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);
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) {
  } 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    11a7 <main+0x67>
jmp    11af <main+0x6f>
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    0xe35(%rip),%rdi
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,%r14
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x64,(%rax)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    0x8(%r14),%rdi
call   1060 <atoi@plt>
cmp    $0xb,%eax
cmovge %r15,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rbx),%esi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [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 %21
20: ; preds = %2
br label %23
21: ; preds = %2
%22 = load i32*, i32** %8
store i32* %22, i32** %6
br label %23
23: ; preds = %21, %20
%24 = load i32*, i32** %7
%25 = call i32 @free(i32* %24)
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %6
%31 = call i32 @free(i32* %30)
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hi mom: %d\0A\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
%9 = select i1 %8, i32* %4, i32* %3
%10 = tail call i32 @free(i32* %4)
%11 = load i32, i32* %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @free(i32* %9)
ret i32 0
}