#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 */
struct buddy2 {
  int dummy;
};

/* Variables and functions */
int buddy2_alloc(struct buddy2 *, int);
int /*<<< orphan*/ buddy2_dump(struct buddy2 *);
int /*<<< orphan*/ buddy2_free(struct buddy2 *, int);
struct buddy2 *buddy2_new(int);
int buddy2_size(struct buddy2 *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int main() {
  char cmd[80];
  int arg;
  struct buddy2 *buddy = buddy2_new(32);
  buddy2_dump(buddy);
  for (;;) {
    scanf("%s %d", cmd, &arg);
    if (strcmp(cmd, "alloc") == 0) {
      printf("allocated@%d\n", buddy2_alloc(buddy, arg));
      buddy2_dump(buddy);
    } else if (strcmp(cmd, "free") == 0) {
      buddy2_free(buddy, arg);
      buddy2_dump(buddy);
    } else if (strcmp(cmd, "size") == 0) {
      printf("size: %d\n", buddy2_size(buddy, arg));
      buddy2_dump(buddy);
    } else
      buddy2_dump(buddy);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x20,%edi
call   1040 <buddy2_new@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
call   1050 <buddy2_dump@plt>
lea    -0x60(%rbp),%rsi
lea    0xe4f(%rip),%rdi
lea    -0x64(%rbp),%rdx
call   1090 <scanf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11fc <main+0x7c>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1070 <buddy2_alloc@plt>
mov    %eax,%esi
lea    0xe23(%rip),%rdi
call   1060 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1050 <buddy2_dump@plt>
jmp    1285 <main+0x105>
lea    -0x60(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1230 <main+0xb0>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1030 <buddy2_free@plt>
mov    -0x70(%rbp),%rdi
call   1050 <buddy2_dump@plt>
jmp    1280 <main+0x100>
lea    -0x60(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1272 <main+0xf2>
mov    -0x70(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   10a0 <buddy2_size@plt>
mov    %eax,%esi
lea    0xdc5(%rip),%rdi
call   1060 <printf@plt>
mov    -0x70(%rbp),%rdi
call   1050 <buddy2_dump@plt>
jmp    127b <main+0xfb>
mov    -0x70(%rbp),%rdi
call   1050 <buddy2_dump@plt>
jmp    1280 <main+0x100>
jmp    1285 <main+0x105>
jmp    11a6 <main+0x26>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    $0x20,%edi
call   1040 <buddy2_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <buddy2_dump@plt>
lea    0xe56(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xe4b(%rip),%r13
lea    0xe58(%rip),%rbp
jmp    11e4 <main+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <buddy2_free@plt>
mov    %rbx,%rdi
call   1050 <buddy2_dump@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <scanf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1240 <main+0xc0>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    %r15,%rdi
lea    0xe03(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11dc <main+0x5c>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   10a0 <buddy2_size@plt>
lea    0xdeb(%rip),%rdi
jmp    1253 <main+0xd3>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1070 <buddy2_alloc@plt>
lea    0xdb9(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
jmp    11dc <main+0x5c>

LLVM IR (-O0):
%struct.buddy2 = type { i32 }
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [6 x i8] c"alloc\00"
@.str.2 = [14 x i8] c"allocated@%d\0A\00"
@.str.3 = [5 x i8] c"free\00"
@.str.4 = [5 x i8] c"size\00"
@.str.5 = [10 x i8] c"size: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32
%4 = alloca %struct.buddy2*
store i32 0, i32* %1
%5 = call %struct.buddy2* @buddy2_new(i32 32)
store %struct.buddy2* %5, %struct.buddy2** %4
%6 = load %struct.buddy2*, %struct.buddy2** %4
%7 = call i32 @buddy2_dump(%struct.buddy2* %6)
br label %8
8: ; preds = %47, %0
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9, i32* %3)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = load %struct.buddy2*, %struct.buddy2** %4
%16 = load i32, i32* %3
%17 = call i32 @buddy2_alloc(%struct.buddy2* %15, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load %struct.buddy2*, %struct.buddy2** %4
%20 = call i32 @buddy2_dump(%struct.buddy2* %19)
br label %47
21: ; preds = %8
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load %struct.buddy2*, %struct.buddy2** %4
%27 = load i32, i32* %3
%28 = call i32 @buddy2_free(%struct.buddy2* %26, i32 %27)
%29 = load %struct.buddy2*, %struct.buddy2** %4
%30 = call i32 @buddy2_dump(%struct.buddy2* %29)
br label %46
31: ; preds = %21
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load %struct.buddy2*, %struct.buddy2** %4
%37 = load i32, i32* %3
%38 = call i32 @buddy2_size(%struct.buddy2* %36, i32 %37)
%39 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %38)
%40 = load %struct.buddy2*, %struct.buddy2** %4
%41 = call i32 @buddy2_dump(%struct.buddy2* %40)
br label %45
42: ; preds = %31
%43 = load %struct.buddy2*, %struct.buddy2** %4
%44 = call i32 @buddy2_dump(%struct.buddy2* %43)
br label %45
45: ; preds = %42, %35
br label %46
46: ; preds = %45, %25
br label %47
47: ; preds = %46, %14
br label %8
}

LLVM IR (-O2):
%struct.buddy2 = type { i32 }
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [6 x i8] c"alloc\00"
@.str.2 = [14 x i8] c"allocated@%d\0A\00"
@.str.3 = [5 x i8] c"free\00"
@.str.4 = [5 x i8] c"size\00"
@.str.5 = [10 x i8] c"size: %d\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call %struct.buddy2* @buddy2_new(i32 32)
%6 = tail call i32 @buddy2_dump(%struct.buddy2* %5)
br label %7
7: ; preds = %28, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3, i32* %2)
%9 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* %2
%13 = call i32 @buddy2_alloc(%struct.buddy2* %5, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %28
15: ; preds = %7
%16 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %2
%20 = call i32 @buddy2_free(%struct.buddy2* %5, i32 %19)
br label %28
21: ; preds = %15
%22 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %2
%26 = call i32 @buddy2_size(%struct.buddy2* %5, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %21, %18, %24, %11
%29 = call i32 @buddy2_dump(%struct.buddy2* %5)
br label %7
}