#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 */
void *malloc(size_t);
int /*<<< orphan*/ suicidef(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ ucommatize(size_t);
void *malloc_or_die(char *id, size_t size) {
  void *p;
  if (size == 0)
    size = 1;
  p = malloc(size);
  if (p == NULL) {
    if (id == NULL)
      suicidef("call to malloc failed to allocate %s bytes", ucommatize(size));
    else
      suicidef("call to malloc failed to allocate %s bytes, for %s",
               ucommatize(size), id);
  };
  ;
  return p;
}


x86 assembly (clang, -O0):
<malloc_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <malloc_or_die+0x23>
movq   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <malloc_or_die+0x86>
cmpq   $0x0,-0x8(%rbp)
jne    1194 <malloc_or_die+0x64>
mov    -0x10(%rbp),%rdi
call   1050 <ucommatize@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <suicidef@plt>
jmp    11b1 <malloc_or_die+0x81>
mov    -0x10(%rbp),%rdi
call   1050 <ucommatize@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <suicidef@plt>
jmp    11b6 <malloc_or_die+0x86>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_or_die>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
mov    $0x1,%ebx
cmovne %rsi,%rbx
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1186 <malloc_or_die+0x56>
mov    %rbx,%rdi
call   1050 <ucommatize@plt>
test   %r14,%r14
je     1176 <malloc_or_die+0x46>
lea    0xec3(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <suicidef@plt>
jmp    1186 <malloc_or_die+0x56>
lea    0xe83(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <suicidef@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"call to malloc failed to allocate %s bytes\00"
@.str.1 = [51 x i8] c"call to malloc failed to allocate %s bytes, for %s\00"
define i8* @malloc_or_die(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i64 1, i64* %4
br label %9
9: ; preds = %8, %2
%10 = load i64, i64* %4
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i64, i64* %4
%19 = call i32 @ucommatize(i64 %18)
%20 = call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %26
21: ; preds = %14
%22 = load i64, i64* %4
%23 = call i32 @ucommatize(i64 %22)
%24 = load i8*, i8** %3
%25 = call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %24)
br label %26
26: ; preds = %21, %17
br label %27
27: ; preds = %26, %9
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
@.str = [43 x i8] c"call to malloc failed to allocate %s bytes\00"
@.str.1 = [51 x i8] c"call to malloc failed to allocate %s bytes, for %s\00"
define noalias i8* @malloc_or_die(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
%4 = select i1 %3, i64 1, i64 %1
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = icmp eq i8* %0, null
%9 = tail call i32 @ucommatize(i64 %4)
br i1 %8, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %14
12: ; preds = %7
%13 = tail call i32 (i8*, i32, ...) @suicidef(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %0)
br label %14
14: ; preds = %10, %12, %2
ret i8* %5
}