#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *p = NULL;
  if ((p = malloc(8)) != NULL) {
    *p = 4;
    printf("%p\t%d\n", p, *p);
  }
  int *q;
  int i;
  q = malloc(10 * sizeof(int));
  if (NULL != q) {
    for (i = 0; i < 10; i++) {
      q[i] = 10 - i;
    }
    for (i = 0; i < 10; i++) {
      printf("%p\tq[%d]=%3d\n", &q[i], i, q[i]);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1171 <main+0x51>
mov    -0x10(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1215 <main+0xf5>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11bd <main+0x9d>
mov    $0xa,%edx
sub    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <main+0x72>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1207 <main+0xe7>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c4 <main+0xa4>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x8,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1169 <main+0x39>
movl   $0x4,(%rax)
lea    0xec6(%rip),%rdi
mov    %rax,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x28,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     12cc <main+0x19c>
mov    %rax,%rbx
lea    0x4(%rax),%r13
lea    0x8(%rax),%r12
lea    0xc(%rax),%rbp
movaps 0xe6e(%rip),%xmm0
movups %xmm0,(%rax)
add    $0x10,%rax
mov    %rax,(%rsp)
lea    0x14(%rbx),%rax
mov    %rax,0x8(%rsp)
lea    0x18(%rbx),%rax
mov    %rax,0x10(%rsp)
lea    0x1c(%rbx),%rax
mov    %rax,0x18(%rsp)
movaps 0xe51(%rip),%xmm0
movups %xmm0,0x10(%rbx)
lea    0x20(%rbx),%rax
mov    %rax,0x20(%rsp)
movabs $0x100000002,%rax
mov    %rax,0x20(%rbx)
mov    %rbx,%r14
add    $0x24,%r14
lea    0xe3f(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    $0xa,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%ecx
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%ecx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%ecx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%ecx
mov    %r15,%rdi
mov    (%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%ecx
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%ecx
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%ecx
mov    %r15,%rdi
mov    0x18(%rsp),%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%ecx
mov    %r15,%rdi
mov    0x20(%rsp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rbx),%ecx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%p\09%d\0A\00"
@.str.1 = [14 x i8] c"%p\09q[%d]=%3d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
%5 = call i32* @malloc(i32 8)
store i32* %5, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = load i32*, i32** %2
store i32 4, i32* %8
%9 = load i32*, i32** %2
%10 = load i32*, i32** %2
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %9, i32 %11)
br label %13
13: ; preds = %7, %0
%14 = call i32* @malloc(i32 40)
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp ne i32* null, %15
br i1 %16, label %17, label %52
17: ; preds = %13
store i32 0, i32* %4
br label %18
18: ; preds = %28, %17
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sub nsw i32 10, %22
%24 = load i32*, i32** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %18
31: ; preds = %18
store i32 0, i32* %4
br label %32
32: ; preds = %47, %31
%33 = load i32, i32* %4
%34 = icmp slt i32 %33, 10
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = load i32*, i32** %3
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %4
%41 = load i32*, i32** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %39, i32 %40, i32 %45)
br label %47
47: ; preds = %35
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %32
50: ; preds = %32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%p\09%d\0A\00"
@.str.1 = [14 x i8] c"%p\09q[%d]=%3d\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 8)
%2 = icmp eq i32* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
store i32 4, i32* %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %1, i32 4)
br label %5
5: ; preds = %3, %0
%6 = tail call i32* @malloc(i32 40)
%7 = icmp eq i32* %6, null
br i1 %7, label %40, label %8
8: ; preds = %5
%9 = getelementptr inbounds i32, i32* %6, i64 1
%10 = getelementptr inbounds i32, i32* %6, i64 2
%11 = getelementptr inbounds i32, i32* %6, i64 3
%12 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 10, i32 9, i32 8, i32 7>, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %6, i64 4
%14 = getelementptr inbounds i32, i32* %6, i64 5
%15 = getelementptr inbounds i32, i32* %6, i64 6
%16 = getelementptr inbounds i32, i32* %6, i64 7
%17 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 6, i32 5, i32 4, i32 3>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %6, i64 8
store i32 2, i32* %18
%19 = getelementptr inbounds i32, i32* %6, i64 9
store i32 1, i32* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 0, i32 10)
%21 = load i32, i32* %9
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32 1, i32 %21)
%23 = load i32, i32* %10
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32 2, i32 %23)
%25 = load i32, i32* %11
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32 3, i32 %25)
%27 = load i32, i32* %13
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %13, i32 4, i32 %27)
%29 = load i32, i32* %14
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32 5, i32 %29)
%31 = load i32, i32* %15
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %15, i32 6, i32 %31)
%33 = load i32, i32* %16
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %16, i32 7, i32 %33)
%35 = load i32, i32* %18
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %18, i32 8, i32 %35)
%37 = load i32, i32* %19
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %19, i32 9, i32 %37)
%39 = tail call i32 @putchar(i32 10)
br label %40
40: ; preds = %8, %5
ret i32 0
}