#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 1) {
    usage(argv[0], "wrong number of arguments");
  }
  int sizes[] = {24, 248, 24, 56, 24, 1016, 24};
  void *ptrs[7];
  int n = 7;
  int i;
  for (i = 0; i < n; i++) {
    ptrs[i] = malloc(sizes[i]);
  }
  for (i = 1; i < n; i += 2) {
    free(ptrs[i]);
  }
  void *ptr = malloc(56);
  for (i = 0; i < n; i++) {
    if (ptr == ptrs[i]) {
      printf("matches i=%d size=%d\n", i, sizes[i]);
      if (i == 1) {
        printf("first-fit\n");
      } else if (i == 3) {
        printf("best-fit\n");
      } else if (i == 5) {
        printf("worst-fit\n");
      } else {
        printf("unknown\n");
      }
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1186 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <usage@plt>
mov    0xed3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xecb(%rip),%eax
mov    %eax,-0x18(%rbp)
movl   $0x7,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    11f1 <main+0xa1>
movslq -0x78(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x78(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11be <main+0x6e>
movl   $0x1,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1220 <main+0xd0>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x78(%rbp)
jmp    11f8 <main+0xa8>
mov    $0x38,%edi
call   1050 <malloc@plt>
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    12f4 <main+0x1a4>
mov    -0x80(%rbp),%rax
movslq -0x78(%rbp),%rcx
cmp    -0x70(%rbp,%rcx,8),%rax
jne    12e1 <main+0x191>
mov    -0x78(%rbp),%esi
movslq -0x78(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x78(%rbp)
jne    128a <main+0x13a>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12dc <main+0x18c>
cmpl   $0x3,-0x78(%rbp)
jne    12a7 <main+0x157>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d7 <main+0x187>
cmpl   $0x5,-0x78(%rbp)
jne    12c4 <main+0x174>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d2 <main+0x182>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d7 <main+0x187>
jmp    12dc <main+0x18c>
jmp    12e1 <main+0x191>
jmp    12e6 <main+0x196>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1235 <main+0xe5>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
je     1159 <main+0x19>
mov    (%rsi),%rdi
lea    0xeac(%rip),%rsi
call   1050 <usage@plt>
mov    $0xf8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x38,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x3f8,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"wrong number of arguments\00"
@__const.main.sizes = [7 x i32] [i32 24, i32 248, i32 24, i32 56, i32 24, i32 1016, i32 24]
@.str.1 = [22 x i8] c"matches i=%d size=%d\0A\00"
@.str.2 = [11 x i8] c"first-fit\0A\00"
@.str.3 = [10 x i8] c"best-fit\0A\00"
@.str.4 = [11 x i8] c"worst-fit\0A\00"
@.str.5 = [9 x i8] c"unknown\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [7 x i32]
%7 = alloca [7 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @usage(i8* %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %13, %2
%19 = bitcast [7 x i32]* %6 to i8*
store i32 7, i32* %8
store i32 0, i32* %9
br label %20
20: ; preds = %33, %18
%21 = load i32, i32* %9
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i8* @malloc(i32 %28)
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 %31
store i8* %29, i8** %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %20
36: ; preds = %20
store i32 1, i32* %9
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 2
store i32 %49, i32* %9
br label %37
50: ; preds = %37
%51 = call i8* @malloc(i32 56)
store i8* %51, i8** %10
store i32 0, i32* %9
br label %52
52: ; preds = %90, %50
%53 = load i32, i32* %9
%54 = load i32, i32* %8
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %93
56: ; preds = %52
%57 = load i8*, i8** %10
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [7 x i8*], [7 x i8*]* %7, i64 0, i64 %59
%61 = load i8*, i8** %60
%62 = icmp eq i8* %57, %61
br i1 %62, label %63, label %89
63: ; preds = %56
%64 = load i32, i32* %9
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %64, i32 %68)
%70 = load i32, i32* %9
%71 = icmp eq i32 %70, 1
br i1 %71, label %72, label %74
72: ; preds = %63
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %88
74: ; preds = %63
%75 = load i32, i32* %9
%76 = icmp eq i32 %75, 3
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %87
79: ; preds = %74
%80 = load i32, i32* %9
%81 = icmp eq i32 %80, 5
br i1 %81, label %82, label %84
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %86
84: ; preds = %79
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %86
86: ; preds = %84, %82
br label %87
87: ; preds = %86, %77
br label %88
88: ; preds = %87, %72
br label %89
89: ; preds = %88, %56
br label %90
90: ; preds = %89
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
store i32 %92, i32* %9
br label %52
93: ; preds = %52
%94 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [26 x i8] c"wrong number of arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %2, %4
%8 = tail call dereferenceable_or_null(248) i8* @malloc(i32 248)
%9 = tail call dereferenceable_or_null(56) i8* @malloc(i32 56)
%10 = tail call dereferenceable_or_null(1016) i8* @malloc(i32 1016)
%11 = tail call i32 @free(i8* %8)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i32 @free(i8* %10)
%14 = tail call i32 @exit(i32 0)
unreachable
}