#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ __WALL;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ child();
int fork();
int /*<<< orphan*/ free(char *);
char *malloc(int);
int waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  pid_t pid, pid2;
  int status;
  char *ptr;
  do {
  } while (0);
  ptr = malloc(123);
  pid = fork();
  assert(pid != -1);
  if (pid == 0) {
    child();
    return 0;
  }
  pid2 = waitpid(-1, &status, __WALL);
  free(malloc(789));
  free(ptr);
  do {
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
jmp    1174 <main+0x14>
mov    $0x7b,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11ba <main+0x5a>
mov    $0x0,%al
call   1030 <child@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fb <main+0x9b>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x10(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x315,%edi
call   1060 <malloc@plt>
mov    %rax,%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
jmp    11f4 <main+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x7b,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1050 <assert@plt>
test   %ebp,%ebp
je     11bf <main+0x5f>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rsi
mov    $0xffffffff,%edi
call   1070 <waitpid@plt>
mov    $0x315,%edi
call   1060 <malloc@plt>
mov    %rax,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
jmp    11c6 <main+0x66>
xor    %eax,%eax
call   1030 <child@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__WALL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
br label %6
6: ; preds = %0
br label %7
7: ; preds = %6
%8 = call i8* @malloc(i32 123)
store i8* %8, i8** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = call i32 (...) @child()
store i32 0, i32* %1
br label %27
18: ; preds = %7
%19 = load i32, i32* @__WALL
%20 = call i32 @waitpid(i32 -1, i32* %4, i32 %19)
store i32 %20, i32* %3
%21 = call i8* @malloc(i32 789)
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %18
br label %26
26: ; preds = %25
store i32 0, i32* %1
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@__WALL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call dereferenceable_or_null(123) i8* @malloc(i32 123)
%4 = tail call i32 (...) @fork()
%5 = icmp ne i32 %4, -1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i32 %4, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 (...) @child()
br label %17
11: ; preds = %0
%12 = load i32, i32* @__WALL
%13 = call i32 @waitpid(i32 -1, i32* %1, i32 %12)
%14 = call dereferenceable_or_null(789) i8* @malloc(i32 789)
%15 = call i32 @free(i8* %14)
%16 = call i32 @free(i8* %3)
br label %17
17: ; preds = %11, %9
ret i32 0
}