#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned long);
int main(void) {
  char *p;
  p = malloc(0);
  printf("malloc(0) = 0x%lx\n", (unsigned long)p);
  free(p);
  p = malloc(-1);
  printf("malloc(-1) = 0x%lx\n", (unsigned long)p);
  free(p);
  p = calloc(0, 1);
  printf("calloc(0,1) = 0x%lx\n", (unsigned long)p);
  free(p);
  p = calloc(0, -1);
  printf("calloc(0,-1) = 0x%lx\n", (unsigned long)p);
  free(p);
  p = calloc(-1, -1);
  printf("calloc(-1,-1) = 0x%lx\n", (unsigned long)p);
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0xffffffff,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%esi
mov    %esi,%edi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe9d(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    $0xffffffff,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
mov    $0xffffffff,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe67(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"malloc(0) = 0x%lx\0A\00"
@.str.1 = [20 x i8] c"malloc(-1) = 0x%lx\0A\00"
@.str.2 = [21 x i8] c"calloc(0,1) = 0x%lx\0A\00"
@.str.3 = [22 x i8] c"calloc(0,-1) = 0x%lx\0A\00"
@.str.4 = [23 x i8] c"calloc(-1,-1) = 0x%lx\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @malloc(i32 0)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = ptrtoint i8* %4 to i64
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = load i8*, i8** %2
%8 = call i32 @free(i8* %7)
%9 = call i8* @malloc(i32 -1)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = ptrtoint i8* %10 to i64
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
%15 = call i8* @calloc(i32 0, i32 1)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = ptrtoint i8* %16 to i64
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %17)
%19 = load i8*, i8** %2
%20 = call i32 @free(i8* %19)
%21 = call i8* @calloc(i32 0, i32 -1)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = ptrtoint i8* %22 to i64
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %23)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
%27 = call i8* @calloc(i32 -1, i32 -1)
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = ptrtoint i8* %28 to i64
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 %29)
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"malloc(0) = 0x%lx\0A\00"
@.str.1 = [20 x i8] c"malloc(-1) = 0x%lx\0A\00"
@.str.2 = [21 x i8] c"calloc(0,1) = 0x%lx\0A\00"
@.str.3 = [22 x i8] c"calloc(0,-1) = 0x%lx\0A\00"
@.str.4 = [23 x i8] c"calloc(-1,-1) = 0x%lx\0A\00"
define i32 @main() {
%1 = tail call i8* @malloc(i32 0)
%2 = ptrtoint i8* %1 to i64
%3 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = tail call i32 @free(i8* %1)
%5 = tail call dereferenceable_or_null(4294967295) i8* @malloc(i32 -1)
%6 = ptrtoint i8* %5 to i64
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%8 = tail call i32 @free(i8* %5)
%9 = tail call i8* @calloc(i32 0, i32 1)
%10 = ptrtoint i8* %9 to i64
%11 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %10)
%12 = tail call i32 @free(i8* %9)
%13 = tail call i8* @calloc(i32 0, i32 -1)
%14 = ptrtoint i8* %13 to i64
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 %14)
%16 = tail call i32 @free(i8* %13)
%17 = tail call dereferenceable_or_null(18446744065119617025) i8* @calloc(i32 -1, i32 -1)
%18 = ptrtoint i8* %17 to i64
%19 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 %18)
%20 = tail call i32 @free(i8* %17)
ret i32 0
}