#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 *calloc(int, int);
int /*<<< orphan*/ printf(char *);
void *my_calloc(size_t num, size_t size) {
  void *temp = calloc(num, size);
  if (!temp) {
    printf("Out of memory\n");
    temp = NULL;
  } else if (!size || !num) {
    printf("Size error\n");
    temp = calloc(1, 1);
  }
  return temp;
}


x86 assembly (clang, -O0):
<my_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1169 <my_calloc+0x49>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
jmp    11a0 <my_calloc+0x80>
cmpq   $0x0,-0x10(%rbp)
je     117f <my_calloc+0x5f>
cmpq   $0x0,-0x8(%rbp)
jne    119b <my_calloc+0x7b>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
jmp    11a0 <my_calloc+0x80>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_calloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <calloc@plt>
test   %rax,%rax
je     1160 <my_calloc+0x40>
test   %rbx,%rbx
je     113e <my_calloc+0x1e>
test   %r14,%r14
jne    116e <my_calloc+0x4e>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <calloc@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
@.str.1 = [12 x i8] c"Size error\0A\00"
define i8* @my_calloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = trunc i64 %6 to i32
%8 = load i64, i64* %4
%9 = trunc i64 %8 to i32
%10 = call i8* @calloc(i32 %7, i32 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %25
15: ; preds = %2
%16 = load i64, i64* %4
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i64, i64* %3
%20 = icmp ne i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %15
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%23 = call i8* @calloc(i32 1, i32 1)
store i8* %23, i8** %5
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %13
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@str = [14 x i8] c"Out of memory\00"
@str.2 = [11 x i8] c"Size error\00"
define noalias i8* @my_calloc(i64 %0, i64 %1) {
%3 = trunc i64 %0 to i32
%4 = trunc i64 %1 to i32
%5 = tail call i8* @calloc(i32 %3, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %16
9: ; preds = %2
%10 = icmp ne i64 %1, 0
%11 = icmp ne i64 %0, 0
%12 = and i1 %11, %10
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.2, i64 0, i64 0))
%15 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
br label %16
16: ; preds = %13, %9, %7
%17 = phi i8* [ %5, %9 ], [ %15, %13 ], [ null, %7 ]
ret i8* %17
}