#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*/ assert(void *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *malloc(size_t);
void *safe_malloc(size_t size) {
  void *ptr = malloc(size);
  do {
    assert(size);
    if (!(size)) {
      exit(EXIT_FAILURE);
    }
  } while (0);
  do {
    assert(ptr);
    if (!(ptr)) {
      exit(EXIT_FAILURE);
    }
  } while (0);
  return ptr;
}


x86 assembly (clang, -O0):
<safe_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)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
jne    116b <safe_malloc+0x3b>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1170 <safe_malloc+0x40>
jmp    1175 <safe_malloc+0x45>
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1197 <safe_malloc+0x67>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    119c <safe_malloc+0x6c>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_malloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <assert@plt>
test   %rbx,%rbx
je     1164 <safe_malloc+0x34>
mov    %r14,%rdi
call   1030 <assert@plt>
test   %r14,%r14
je     1164 <safe_malloc+0x34>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i8* @safe_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
br label %6
6: ; preds = %1
%7 = load i64, i64* %2
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @assert(i8* %8)
%10 = load i64, i64* %2
%11 = icmp ne i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %6
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
%18 = load i8*, i8** %3
%19 = call i32 @assert(i8* %18)
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
br label %26
26: ; preds = %25
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i8* @safe_malloc(i64 %0) {
%2 = tail call i8* @malloc(i64 %0)
%3 = inttoptr i64 %0 to i8*
%4 = tail call i32 @assert(i8* %3)
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i32 @assert(i8* %2)
%11 = icmp eq i8* %2, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %9
ret i8* %2
}