#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int main() {
  char *some_memory;
  int megabyte = (1024 * 1024);
  int exit_code = EXIT_FAILURE;
  some_memory = (char *)malloc(megabyte);
  if (some_memory != NULL) {
    sprintf(some_memory, "Hello, World!\n");
    printf("%s", some_memory);
    exit_code = EXIT_SUCCESS;
  }
  return (exit_code);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x100000,-0x14(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1195 <main+0x65>
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb8(%rip),%rax
mov    (%rax),%ebx
mov    $0x100000,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     116c <main+0x4c>
movabs $0xa21646c726f57,%rcx
mov    %rcx,0x7(%rax)
movabs $0x57202c6f6c6c6548,%rcx
2c 20 57
mov    %rcx,(%rax)
lea    0xeb4(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [15 x i8] c"Hello, World!\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1048576, i32* %3
%5 = load i32, i32* @EXIT_FAILURE
store i32 %5, i32* %4
%6 = load i32, i32* %3
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_SUCCESS
store i32 %16, i32* %4
br label %17
17: ; preds = %11, %0
%18 = load i32, i32* %4
ret i32 %18
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [15 x i8] c"Hello, World!\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @EXIT_FAILURE
%2 = tail call i64 @malloc(i32 1048576)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %8, label %5
5: ; preds = %0
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(15) %3, i8* align 1 dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 15, i1 false)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i32, i32* @EXIT_SUCCESS
br label %8
8: ; preds = %5, %0
%9 = phi i32 [ %7, %5 ], [ %1, %0 ]
ret i32 %9
}