#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, char const *,
                           int);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *allocate_worker(size_t size, const char *file, int line) {
  void *ptr = NULL;
  if (size > 0) {
    ptr = malloc(size);
    if (ptr == NULL) {
      fprintf(stderr, "Failure allocating %ld bytes in file %s, line %d", size,
              file, line);
      exit(1);
    }
    memset(ptr, 0, size);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<allocate_worker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    11b8 <allocate_worker+0x78>
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <allocate_worker+0x69>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_worker>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <allocate_worker+0x31>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <malloc@plt>
test   %rax,%rax
je     1181 <allocate_worker+0x41>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
jmp    1173 <allocate_worker+0x33>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Failure allocating %ld bytes in file %s, line %d\00"
define i8* @allocate_worker(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
%8 = load i64, i64* %4
%9 = icmp ugt i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %3
%11 = load i64, i64* %4
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i64, i64* %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %17, i8* %18, i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %10
%23 = load i8*, i8** %7
%24 = load i64, i64* %4
%25 = call i32 @memset(i8* %23, i32 0, i64 %24)
br label %26
26: ; preds = %22, %3
%27 = load i8*, i8** %7
ret i8* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Failure allocating %ld bytes in file %s, line %d\00"
define i8* @allocate_worker(i64 %0, i8* %1, i32 %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i8* @malloc(i64 %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i64 %0, i8* %1, i32 %2)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = tail call i32 @memset(i8* %6, i32 0, i64 %0)
br label %14
14: ; preds = %12, %3
%15 = phi i8* [ %6, %12 ], [ null, %3 ]
ret i8* %15
}