#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*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           unsigned long);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
void *_tc_zalloc(const char *file, int line, size_t size) {
  void *p = malloc(size);
  if (p == NULL) {
    fprintf(stderr, "[%s:%d] tc_zalloc(): can't allocate %lu bytes\n", file,
            line, (unsigned long)size);
  } else {
    memset(p, 0, size);
  }
  return p;
}


x86 assembly (clang, -O0):
<_tc_zalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1180 <_tc_zalloc+0x50>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe8a(%rip),%rsi
call   1040 <fprintf@plt>
jmp    118f <_tc_zalloc+0x5f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tc_zalloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <_tc_zalloc+0x2f>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
jmp    117d <_tc_zalloc+0x4d>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %rbp,%rdx
mov    %r15d,%ecx
mov    %r14,%r8
call   1040 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"[%s:%d] tc_zalloc(): can't allocate %lu bytes\0A\00"
define i8* @_tc_zalloc(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = load i64, i64* %6
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i64 %16)
br label %22
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i64, i64* %6
%21 = call i32 @memset(i8* %19, i32 0, i64 %20)
br label %22
22: ; preds = %18, %12
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"[%s:%d] tc_zalloc(): can't allocate %lu bytes\0A\00"
define i8* @_tc_zalloc(i8* %0, i32 %1, i64 %2) {
%4 = tail call i8* @malloc(i64 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i64 %2)
br label %11
9: ; preds = %3
%10 = tail call i32 @memset(i8* %4, i32 0, i64 %2)
br label %11
11: ; preds = %9, %6
ret i8* %4
}