#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 const);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int main(int argc, char *argv[]) {
  const int N = 10;
  int i;
  int *p = (int *)malloc(N * sizeof(int));
  printf("main: Putting %d random numbers in allocated memory\n", N);
  for (i = 0; i < N; ++i) {
    p[i] = rand();
  }
  printf("main: The %d random numbers are ", N);
  for (i = 0; i < N; ++i) {
    printf("%d,", p[i]);
  }
  printf("\n");
  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)
movl   $0xa,-0x14(%rbp)
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11a1 <main+0x71>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <main+0x45>
lea    0xe8d(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11ec <main+0xbc>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <main+0x8b>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x4(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x8(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0xc(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x10(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x14(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x18(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x1c(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x20(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x24(%rbx)
lea    0xe67(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xe73(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [53 x i8] c"main: Putting %d random numbers in allocated memory\0A\00"
@.str.1 = [33 x i8] c"main: The %d random numbers are \00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
%9 = call i64 @malloc(i32 40)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %8
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 10)
store i32 0, i32* %7
br label %12
12: ; preds = %21, %2
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = load i32*, i32** %8
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 %16, i32* %20
br label %21
21: ; preds = %15
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %12
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 10)
store i32 0, i32* %7
br label %26
26: ; preds = %36, %24
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 10
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32*, i32** %8
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %26
39: ; preds = %26
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"main: Putting %d random numbers in allocated memory\0A\00"
@.str.1 = [33 x i8] c"main: The %d random numbers are \00"
@.str.2 = [4 x i8] c"%d,\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 40)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 10)
%6 = tail call i32 (...) @rand()
store i32 %6, i32* %4
%7 = tail call i32 (...) @rand()
%8 = getelementptr inbounds i32, i32* %4, i64 1
store i32 %7, i32* %8
%9 = tail call i32 (...) @rand()
%10 = getelementptr inbounds i32, i32* %4, i64 2
store i32 %9, i32* %10
%11 = tail call i32 (...) @rand()
%12 = getelementptr inbounds i32, i32* %4, i64 3
store i32 %11, i32* %12
%13 = tail call i32 (...) @rand()
%14 = getelementptr inbounds i32, i32* %4, i64 4
store i32 %13, i32* %14
%15 = tail call i32 (...) @rand()
%16 = getelementptr inbounds i32, i32* %4, i64 5
store i32 %15, i32* %16
%17 = tail call i32 (...) @rand()
%18 = getelementptr inbounds i32, i32* %4, i64 6
store i32 %17, i32* %18
%19 = tail call i32 (...) @rand()
%20 = getelementptr inbounds i32, i32* %4, i64 7
store i32 %19, i32* %20
%21 = tail call i32 (...) @rand()
%22 = getelementptr inbounds i32, i32* %4, i64 8
store i32 %21, i32* %22
%23 = tail call i32 (...) @rand()
%24 = getelementptr inbounds i32, i32* %4, i64 9
store i32 %23, i32* %24
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 10)
%26 = load i32, i32* %4
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %8
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %10
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %12
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %14
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %16
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %18
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %20
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %22
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %24
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = tail call i32 @putchar(i32 10)
ret i32 0
}