#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 /*<<< orphan*/ ptr;

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gets(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main() {
  setvbuf(stdout, 0, _IONBF, 0);
  int cmd, idx, sz;
  char *ptr[10];
  memset(ptr, 0, sizeof(ptr));
  puts("1. malloc + gets\n2. free\n3. puts");
  while (1) {
    printf("> ");
    scanf("%d %d", &cmd, &idx);
    idx %= 10;
    if (cmd == 1) {
      scanf("%d%*c", &sz);
      ptr[idx] = malloc(sz);
      gets(ptr[idx]);
    } else if (cmd == 2) {
      free(ptr[idx]);
    } else if (cmd == 3) {
      puts(ptr[idx]);
    } else {
      exit(0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
mov    %ecx,%esi
call   1090 <setvbuf@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
lea    0xe2f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
lea    0xe3b(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1249 <main+0xb9>
lea    0xe13(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   10a0 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
movslq -0xc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1070 <gets@plt>
jmp    1294 <main+0x104>
cmpl   $0x2,-0x8(%rbp)
jne    1266 <main+0xd6>
movslq -0xc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1030 <free@plt>
jmp    128f <main+0xff>
cmpl   $0x3,-0x8(%rbp)
jne    1283 <main+0xf3>
movslq -0xc(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rdi
call   1040 <puts@plt>
jmp    128a <main+0xfa>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    128f <main+0xff>
jmp    1294 <main+0x104>
jmp    11d6 <main+0x46>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
lea    0xe2f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe44(%rip),%r14
lea    0xe40(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x4(%rsp),%rbx
lea    0xe35(%rip),%r13
lea    0x8(%rsp),%rbp
jmp    120c <main+0x7c>
nopl   0x0(%rax)
cltq
mov    0x10(%rsp,%rax,8),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <scanf@plt>
movslq 0x4(%rsp),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
mov    0xc(%rsp),%ecx
cmp    $0x3,%ecx
je     1290 <main+0x100>
cmp    $0x2,%ecx
je     1200 <main+0x70>
cmp    $0x1,%ecx
jne    12a1 <main+0x111>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
mov    0x8(%rsp),%edi
call   1080 <malloc@plt>
movslq 0x4(%rsp),%rcx
mov    %rax,0x10(%rsp,%rcx,8)
mov    %rax,%rdi
call   1070 <gets@plt>
jmp    120c <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
nop
cltq
mov    0x10(%rsp,%rax,8),%rdi
call   1040 <puts@plt>
jmp    120c <main+0x7c>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [33 x i8] c"1. malloc + gets\0A2. free\0A3. puts\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [6 x i8] c"%d%*c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8*]
store i32 0, i32* %1
%6 = load i32, i32* @stdout
%7 = load i32, i32* @_IONBF
%8 = call i32 @setvbuf(i32 %6, i32 0, i32 %7, i32 0)
%9 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 0
%10 = call i32 @memset(i8** %9, i32 0, i32 80)
%11 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %0, %53
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%15 = load i32, i32* %3
%16 = srem i32 %15, 10
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %31
19: ; preds = %12
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %4
%22 = call i8* @malloc(i32 %21)
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %24
store i8* %22, i8** %25
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @gets(i8* %29)
br label %53
31: ; preds = %12
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @free(i8* %38)
br label %52
40: ; preds = %31
%41 = load i32, i32* %2
%42 = icmp eq i32 %41, 3
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @puts(i8* %47)
br label %51
49: ; preds = %40
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %43
br label %52
52: ; preds = %51, %34
br label %53
53: ; preds = %52, %19
br label %12
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [33 x i8] c"1. malloc + gets\0A2. free\0A3. puts\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [6 x i8] c"%d%*c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8*]
%5 = load i32, i32* @stdout
%6 = load i32, i32* @_IONBF
%7 = tail call i32 @setvbuf(i32 %5, i32 0, i32 %6, i32 0)
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast [10 x i8*]* %4 to i8*
%12 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%13 = call i32 @memset(i8** %12, i32 0, i32 80)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %34, %0
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2)
%18 = load i32, i32* %2
%19 = srem i32 %18, 10
store i32 %19, i32* %2
%20 = load i32, i32* %1
switch i32 %20, label %40 [
i32 1, label %21
i32 2, label %29
i32 3, label %35
]
21: ; preds = %15
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = call i8* @malloc(i32 %23)
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %26
store i8* %24, i8** %27
%28 = call i32 @gets(i8* %24)
br label %34
29: ; preds = %15
%30 = sext i32 %19 to i64
%31 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %29, %35, %21
br label %15
35: ; preds = %15
%36 = sext i32 %19 to i64
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @puts(i8* dereferenceable(1) %38)
br label %34
40: ; preds = %15
%41 = call i32 @exit(i32 0)
unreachable
}