#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(size_t);
int /*<<< orphan*/ stderr;
void *mrsh_malloc(size_t size) {
  void *ret = malloc(size);
  if (ret == NULL)
    do {
      do {
        fprintf(stderr, "mrsh: ");
        fprintf(stderr, "allocation error");
        fprintf(stderr, "\n");
      } while (0);
      exit(EXIT_FAILURE);
    } while (0);
  return ret;
}


x86 assembly (clang, -O0):
<mrsh_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ab <mrsh_malloc+0x7b>
jmp    1159 <mrsh_malloc+0x29>
jmp    115e <mrsh_malloc+0x2e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrsh_malloc>:
push   %rbx
call   1040 <malloc@plt>
test   %rax,%rax
je     113d <mrsh_malloc+0xd>
pop    %rbx
ret
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%edi
lea    0xeb3(%rip),%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeac(%rip),%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeaf(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"mrsh: \00"
@.str.1 = [17 x i8] c"allocation error\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @mrsh_malloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = call i8* @malloc(i64 %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %21
8: ; preds = %1
br label %9
9: ; preds = %8
br label %10
10: ; preds = %9
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %10
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; No predecessors!
br label %21
21: ; preds = %20, %1
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"mrsh: \00"
@.str.1 = [17 x i8] c"allocation error\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @mrsh_malloc(i64 %0) {
%2 = tail call i8* @malloc(i64 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
ret i8* %2
}