#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  printf("Hello world!\n");
  int *pI;
  pI = (int *)malloc(10 * sizeof(int));
  printf("Let's leak a pointer to an array of 10 ints\n");
  int i = 0;
  for (i = 0; i < 9; i++) {
    pI[i] = 303 + i;
  }
  int j = 0;
  for (j = 0; j < 9; j++) {
    if (pI[j] != 303 + j)
      printf("  Something strange is happening...\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    118f <main+0x6f>
mov    -0x14(%rbp),%edx
add    $0x12f,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <main+0x43>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x9,-0x18(%rbp)
jge    11e2 <main+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%ecx
add    $0x12f,%ecx
cmp    %ecx,%eax
je     11cf <main+0xaf>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    11d4 <main+0xb4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119d <main+0x7d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
movaps 0xeb3(%rip),%xmm0
movups %xmm0,(%rbx)
movaps 0xeb9(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movl   $0x137,0x20(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello world!\0A\00"
@.str.1 = [45 x i8] c"Let's leak a pointer to an array of 10 ints\0A\00"
@.str.2 = [37 x i8] c" Something strange is happening...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @malloc(i32 40)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
store i32 0, i32* %3
br label %9
9: ; preds = %19, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 9
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %3
%14 = add nsw i32 303, %13
%15 = load i32*, i32** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
br label %19
19: ; preds = %12
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %9
22: ; preds = %9
store i32 0, i32* %4
store i32 0, i32* %4
br label %23
23: ; preds = %38, %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 9
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = load i32*, i32** %2
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %4
%33 = add nsw i32 303, %32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %23
41: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@str = [13 x i8] c"Hello world!\00"
@str.3 = [44 x i8] c"Let's leak a pointer to an array of 10 ints\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 40)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
%5 = inttoptr i64 %2 to <4 x i32>*
store <4 x i32> <i32 303, i32 304, i32 305, i32 306>, <4 x i32>* %5
%6 = getelementptr inbounds i32, i32* %3, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 307, i32 308, i32 309, i32 310>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %3, i64 8
store i32 311, i32* %8
ret i32 0
}