#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 mem_block_init();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rte_free(void *);
void *rte_malloc(int);
int main(void) {
  int ret = 0;
  void *ptr = NULL;
  ret = mem_block_init();
  if (ret < 0) {
    return -1;
  }
  ptr = rte_malloc(65535);
  if (NULL == ptr) {
    printf("Failed to malloc.\n");
  }
  printf("ptr = %p\n", ptr);
  rte_free(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <mem_block_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117e <main+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <main+0x88>
mov    $0xffff,%edi
call   1030 <rte_malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11a6 <main+0x66>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <rte_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <mem_block_init@plt>
test   %eax,%eax
js     1199 <main+0x49>
mov    $0xffff,%edi
call   1040 <rte_malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117c <main+0x2c>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7d(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <rte_free@plt>
jmp    119e <main+0x4e>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Failed to malloc.\0A\00"
@.str.1 = [10 x i8] c"ptr = %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i8* null, i8** %3
%4 = call i32 (...) @mem_block_init()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %19
8: ; preds = %0
%9 = call i8* @rte_malloc(i32 65535)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp eq i8* null, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i8*, i8** %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %3
%18 = call i32 @rte_free(i8* %17)
store i32 0, i32* %1
br label %19
19: ; preds = %14, %7
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"ptr = %p\0A\00"
@str = [18 x i8] c"Failed to malloc.\00"
define i32 @main() {
%1 = tail call i32 (...) @mem_block_init()
%2 = icmp slt i32 %1, 0
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call i8* @rte_malloc(i32 65535)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = tail call i32 @rte_free(i8* %4)
br label %11
11: ; preds = %0, %8
%12 = phi i32 [ 0, %8 ], [ -1, %0 ]
ret i32 %12
}