#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*/ init_save_alloc();
int /*<<< orphan*/ printf(char *);
char *save_alloc(int);
scalar_t__ save_free(char *);
int main(int argc, char **argv) {
  init_save_alloc();
  char *ptr = save_alloc(2000);
  ptr[0] = '1';
  char *ptr2 = save_alloc(2001);
  ptr2[0] = '2';
  char *ptr3 = save_alloc(233);
  ptr3[0] = '3';
  char *ptr4 = save_alloc(12);
  ptr4[0] = '4';
  if (save_free(ptr) != 0) {
    printf("1\n");
    return 1;
  }
  if (save_free(ptr3) != 0) {
    printf("3\n");
    return 3;
  }
  if (save_free(ptr4) != 0) {
    printf("4\n");
    return 4;
  }
  if (save_free(ptr2) != 0) {
    printf("2\n");
    return 2;
  }
  return 0;
}


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    $0x0,%al
call   1060 <init_save_alloc@plt>
mov    $0x7d0,%edi
call   1040 <save_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x31,(%rax)
mov    $0x7d1,%edi
call   1040 <save_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x32,(%rax)
mov    $0xe9,%edi
call   1040 <save_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x33,(%rax)
mov    $0xc,%edi
call   1040 <save_alloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x34,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <save_free@plt>
cmp    $0x0,%rax
je     11dc <main+0x9c>
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    -0x28(%rbp),%rdi
call   1050 <save_free@plt>
cmp    $0x0,%rax
je     1207 <main+0xc7>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    -0x30(%rbp),%rdi
call   1050 <save_free@plt>
cmp    $0x0,%rax
je     1232 <main+0xf2>
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    -0x20(%rbp),%rdi
call   1050 <save_free@plt>
cmp    $0x0,%rax
je     125d <main+0x11d>
lea    0xdbd(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1264 <main+0x124>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <init_save_alloc@plt>
mov    $0x7d0,%edi
call   1040 <save_alloc@plt>
mov    %rax,%rbx
movb   $0x31,(%rax)
mov    $0x7d1,%edi
call   1040 <save_alloc@plt>
mov    %rax,%r14
movb   $0x32,(%rax)
mov    $0xe9,%edi
call   1040 <save_alloc@plt>
mov    %rax,%r12
movb   $0x33,(%rax)
mov    $0xc,%edi
call   1040 <save_alloc@plt>
mov    %rax,%r15
movb   $0x34,(%rax)
mov    %rbx,%rdi
call   1050 <save_free@plt>
test   %rax,%rax
je     11aa <main+0x6a>
mov    $0x1,%ebx
lea    0xe5e(%rip),%rdi
jmp    11f9 <main+0xb9>
mov    %r12,%rdi
call   1050 <save_free@plt>
test   %rax,%rax
je     11c5 <main+0x85>
mov    $0x3,%ebx
lea    0xe41(%rip),%rdi
jmp    11f9 <main+0xb9>
mov    %r15,%rdi
call   1050 <save_free@plt>
test   %rax,%rax
je     11e0 <main+0xa0>
mov    $0x4,%ebx
lea    0xe24(%rip),%rdi
jmp    11f9 <main+0xb9>
mov    %r14,%rdi
call   1050 <save_free@plt>
test   %rax,%rax
je     120c <main+0xcc>
mov    $0x2,%ebx
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
jmp    11fe <main+0xbe>

LLVM IR (-O0):
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [3 x i8] c"3\0A\00"
@.str.2 = [3 x i8] c"4\0A\00"
@.str.3 = [3 x i8] c"2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @init_save_alloc()
%11 = call i8* @save_alloc(i32 2000)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 49, i8* %13
%14 = call i8* @save_alloc(i32 2001)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 50, i8* %16
%17 = call i8* @save_alloc(i32 233)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 51, i8* %19
%20 = call i8* @save_alloc(i32 12)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 52, i8* %22
%23 = load i8*, i8** %6
%24 = call i64 @save_free(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
28: ; preds = %2
%29 = load i8*, i8** %8
%30 = call i64 @save_free(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %3
br label %47
34: ; preds = %28
%35 = load i8*, i8** %9
%36 = call i64 @save_free(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %3
br label %47
40: ; preds = %34
%41 = load i8*, i8** %7
%42 = call i64 @save_free(i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %47
46: ; preds = %40
store i32 0, i32* %3
br label %47
47: ; preds = %46, %44, %38, %32, %26
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@str = [2 x i8] c"2\00"
@str.4 = [2 x i8] c"4\00"
@str.5 = [2 x i8] c"3\00"
@str.6 = [2 x i8] c"1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @init_save_alloc()
%4 = tail call i8* @save_alloc(i32 2000)
store i8 49, i8* %4
%5 = tail call i8* @save_alloc(i32 2001)
store i8 50, i8* %5
%6 = tail call i8* @save_alloc(i32 233)
store i8 51, i8* %6
%7 = tail call i8* @save_alloc(i32 12)
store i8 52, i8* %7
%8 = tail call i64 @save_free(i8* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = tail call i64 @save_free(i8* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = tail call i64 @save_free(i8* %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i64 @save_free(i8* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16, %13, %10, %2
%20 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %10 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0), %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %16 ]
%21 = phi i32 [ 1, %2 ], [ 3, %10 ], [ 4, %13 ], [ 2, %16 ]
%22 = tail call i32 @puts(i8* dereferenceable(1) %20)
br label %23
23: ; preds = %19, %16
%24 = phi i32 [ 0, %16 ], [ %21, %19 ]
ret i32 %24
}