#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 */
scalar_t__ mbox_property(int, unsigned int *);
unsigned mem_alloc(int file_desc, unsigned size, unsigned align,
                   unsigned flags) {
  int i = 0;
  unsigned p[32];
  p[i++] = 0;
  p[i++] = 0x00000000;
  p[i++] = 0x3000c;
  p[i++] = 12;
  p[i++] = 12;
  p[i++] = size;
  p[i++] = align;
  p[i++] = flags;
  p[i++] = 0x00000000;
  p[0] = i * sizeof *p;
  if (mbox_property(file_desc, p) < 0)
    return (unsigned)~0;
  else
    return p[5];
}


x86 assembly (clang, -O0):
<mem_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0x0,-0xa0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0x0,-0xa0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0x3000c,-0xa0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0xc,-0xa0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0xc,-0xa0(%rbp,%rax,4)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movl   $0x0,-0xa0(%rbp,%rax,4)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0xa0(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
call   1030 <mbox_property@plt>
cmp    $0x0,%rax
jge    1236 <mem_alloc+0x126>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <mem_alloc+0x12f>
mov    -0x8c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_alloc>:
sub    $0x88,%rsp
movl   $0xc,0x10(%rsp)
mov    %esi,0x14(%rsp)
mov    %edx,0x18(%rsp)
mov    %ecx,0x1c(%rsp)
movl   $0x0,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
call   1030 <mbox_property@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     1157 <mem_alloc+0x47>
mov    0x14(%rsp),%eax
add    $0x88,%rsp
ret

LLVM IR (-O0):
define i32 @mem_alloc(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [32 x i32]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %10
%13 = add nsw i32 %12, 1
store i32 %13, i32* %10
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %14
store i32 0, i32* %15
%16 = load i32, i32* %10
%17 = add nsw i32 %16, 1
store i32 %17, i32* %10
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %18
store i32 0, i32* %19
%20 = load i32, i32* %10
%21 = add nsw i32 %20, 1
store i32 %21, i32* %10
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %22
store i32 196620, i32* %23
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
store i32 %25, i32* %10
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %26
store i32 12, i32* %27
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %30
store i32 12, i32* %31
%32 = load i32, i32* %7
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %35
store i32 %32, i32* %36
%37 = load i32, i32* %8
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %40
store i32 %37, i32* %41
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %45
store i32 %42, i32* %46
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %49
store i32 0, i32* %50
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = mul i64 %52, 4
%54 = trunc i64 %53 to i32
%55 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 0
store i32 %54, i32* %55
%56 = load i32, i32* %6
%57 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 0
%58 = call i64 @mbox_property(i32 %56, i32* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %4
store i32 -1, i32* %5
br label %64
61: ; preds = %4
%62 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 5
%63 = load i32, i32* %62
store i32 %63, i32* %5
br label %64
64: ; preds = %61, %60
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
define i32 @mem_alloc(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [32 x i32]
%6 = bitcast [32 x i32]* %5 to i8*
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 4
store i32 12, i32* %8
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 5
store i32 %1, i32* %9
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 6
store i32 %2, i32* %10
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 7
store i32 %3, i32* %11
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 8
store i32 0, i32* %12
%13 = bitcast [32 x i32]* %5 to <4 x i32>*
store <4 x i32> <i32 36, i32 0, i32 196620, i32 12>, <4 x i32>* %13
%14 = call i64 @mbox_property(i32 %0, i32* %7)
%15 = icmp slt i64 %14, 0
%16 = load i32, i32* %9
%17 = select i1 %15, i32 -1, i32 %16
ret i32 %17
}