#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 */
scalar_t__ ADM_alloc(unsigned long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long, char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ stderr;
void *twolame_malloc(unsigned long block, char *item) {
  void *ptr;
  ptr = (void *)ADM_alloc(block);
  if (ptr != NULL) {
    memset(ptr, 0, block);
  } else {
    fprintf(stderr, "Unable to allocate %ld bytes for %s\n", block, item);
    return NULL;
  }
  return (ptr);
}


x86 assembly (clang, -O0):
<twolame_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ADM_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116c <twolame_malloc+0x3c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    1196 <twolame_malloc+0x66>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    119e <twolame_malloc+0x6e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twolame_malloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <ADM_alloc@plt>
test   %rax,%rax
je     1157 <twolame_malloc+0x27>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
jmp    1174 <twolame_malloc+0x44>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Unable to allocate %ld bytes for %s\0A\00"
define i8* @twolame_malloc(i64 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
%7 = load i64, i64* %4
%8 = call i64 @ADM_alloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i64, i64* %4
%15 = call i32 @memset(i8* %13, i32 0, i64 %14)
br label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i64, i64* %4
%19 = load i8*, i8** %5
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %18, i8* %19)
store i8* null, i8** %3
br label %23
21: ; preds = %12
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %16
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Unable to allocate %ld bytes for %s\0A\00"
define i8* @twolame_malloc(i64 %0, i8* %1) {
%3 = tail call i64 @ADM_alloc(i64 %0)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @memset(i8* %4, i32 0, i64 %0)
br label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %0, i8* %1)
br label %11
11: ; preds = %6, %8
%12 = phi i8* [ %4, %6 ], [ null, %8 ]
ret i8* %12
}