#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 *calloc(int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int, int, int, int);
int *realloc(int /*<<< orphan*/ *, int);
void func2() {
  int *ptr1 = malloc(sizeof(int));
  int *ptr2 = realloc(NULL, sizeof(int));
  int *ptr3 = calloc(1, sizeof(int));
  int *ptr4 = calloc(sizeof(int), 1);
  printf("%d %d %d %d\n", *ptr1, *ptr2, *ptr3, *ptr4);
  free(ptr1);
  free(ptr2);
  free(ptr3);
  free(ptr4);
}


x86 assembly (clang, -O0):
<func2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8d
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    $0x4,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    $0x1,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    $0x4,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    (%r14),%esi
mov    (%r15),%edx
mov    (%r12),%ecx
mov    (%rax),%r8d
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"%d %d %d %d\0A\00"
define void @func2() {
%1 = tail call i32* @malloc(i32 4)
%2 = tail call i32* @realloc(i32* null, i32 4)
%3 = tail call i32* @calloc(i32 1, i32 4)
%4 = tail call i32* @calloc(i32 4, i32 1)
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %7, i32 %8)
%10 = tail call i32 @free(i32* %1)
%11 = tail call i32 @free(i32* %2)
%12 = tail call i32 @free(i32* %3)
%13 = tail call i32 @free(i32* %4)
ret void
}