#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*/ fprintf(int /*<<< orphan*/, char *);
void *na_malloc(size_t);
int /*<<< orphan*/ printf(char *, intptr_t);
int /*<<< orphan*/ read_long(long *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
bool alloc_command(void) {
  long size;
  if (!read_long(&size, 0)) {
    fprintf(stderr, "Invalid size\n");
    return false;
  }
  void *mem = na_malloc((size_t)size);
  printf("Allocated memory at 0x%08lx\n", (intptr_t)mem);
}


x86 assembly (clang, -O0):
<alloc_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <read_long@plt>
cmp    $0x0,%eax
jne    117d <alloc_command+0x3d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    119a <alloc_command+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <na_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_command>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <read_long@plt>
test   %eax,%eax
je     1169 <alloc_command+0x29>
mov    (%rsp),%rdi
call   1030 <na_malloc@plt>
lea    0xeaf(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    117e <alloc_command+0x3e>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Invalid size\0A\00"
@.str.1 = [29 x i8] c"Allocated memory at 0x%08lx\0A\00"
define i32 @alloc_command() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = call i32 @read_long(i64* %2, i32 0)
%5 = icmp ne i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %15
9: ; preds = %0
%10 = load i64, i64* %2
%11 = call i8* @na_malloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %12 to i64
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %9, %6
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Invalid size\0A\00"
@.str.1 = [29 x i8] c"Allocated memory at 0x%08lx\0A\00"
define i32 @alloc_command() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @read_long(i64* %1, i32 0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
8: ; preds = %0
%9 = load i64, i64* %1
%10 = call i8* @na_malloc(i64 %9)
%11 = ptrtoint i8* %10 to i64
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %13
13: ; preds = %8, %5
ret i32 0
}