#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 *, ...);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  fprintf(stderr, "malloc some memory!\n");
  void *ptr1 = malloc(1024);
  fprintf(stderr, "ptr1: %p\n", ptr1);
  if (!ptr1)
    fprintf(stderr, "handle ptr1 error\n");
  void *ptr2 = malloc(28);
  fprintf(stderr, "ptr2: %p\n", ptr2);
  if (!ptr2)
    fprintf(stderr, "handle ptr2 error\n");
  free(ptr1);
  free(ptr2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <main+0x78>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1c,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <main+0xc3>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2ea4(%rip),%r15
mov    (%r15),%edi
lea    0xeba(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%r15),%edi
lea    0xeb1(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r14,%r14
jne    1184 <main+0x54>
mov    (%r15),%edi
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1c,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%edi
lea    0xe97(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %rbx,%rbx
jne    11bb <main+0x8b>
mov    (%r15),%edi
lea    0xe88(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"malloc some memory!\0A\00"
@.str.1 = [10 x i8] c"ptr1: %p\0A\00"
@.str.2 = [19 x i8] c"handle ptr1 error\0A\00"
@.str.3 = [10 x i8] c"ptr2: %p\0A\00"
@.str.4 = [19 x i8] c"handle ptr2 error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i8* @malloc(i32 1024)
store i8* %10, i8** %6
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %6
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
%20 = call i8* @malloc(i32 28)
store i8* %20, i8** %7
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %7
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %26, %19
%30 = load i8*, i8** %6
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"malloc some memory!\0A\00"
@.str.1 = [10 x i8] c"ptr1: %p\0A\00"
@.str.2 = [19 x i8] c"handle ptr1 error\0A\00"
@.str.3 = [10 x i8] c"ptr2: %p\0A\00"
@.str.4 = [19 x i8] c"handle ptr2 error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = icmp eq i8* %5, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = tail call dereferenceable_or_null(28) i8* @malloc(i32 28)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%16 = icmp eq i8* %13, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %17, %12
%21 = tail call i32 @free(i8* %5)
%22 = tail call i32 @free(i8* %13)
ret i32 0
}