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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
void *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
void *gmalloc(size_t size) {
  void *ptr;
  if (size == 0) {
    printf("gmalloc: zero size\n");
    exit(-1);
  }
  ptr = malloc(size);
  if (ptr == NULL) {
    printf("gmalloc: out of memory (allocating %lu bytes)\n", (u_long)size);
    exit(-1);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<gmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115f <gmalloc+0x2f>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <gmalloc+0x65>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gmalloc>:
push   %rbx
test   %rdi,%rdi
je     1155 <gmalloc+0x15>
mov    %rdi,%rbx
call   1050 <malloc@plt>
test   %rax,%rax
je     116b <gmalloc+0x2b>
pop    %rbx
ret
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe8e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"gmalloc: zero size\0A\00"
@.str.1 = [47 x i8] c"gmalloc: out of memory (allocating %lu bytes)\0A\00"
define i8* @gmalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %1
%10 = load i64, i64* %2
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i64, i64* %2
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %9
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"gmalloc: out of memory (allocating %lu bytes)\0A\00"
@str = [19 x i8] c"gmalloc: zero size\00"
define noalias i8* @gmalloc(i64 %0) {
%2 = icmp eq i64 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 -1)
unreachable
6: ; preds = %1
%7 = tail call i8* @malloc(i64 %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = trunc i64 %0 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %6
ret i8* %7
}