#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(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int, char const);
int /*<<< orphan*/ stderr;
int main(void) {
  int array[10];
  int *array2 = malloc(10 * sizeof(int));
  if (NULL == array2) {
    fprintf(stderr, "malloc failed\n");
    return (-1);
  }
  int i;
  const char *string = "Foobar.";
  for (i = 0; i < 10; i++) {
    array[i] = i;
    *(array2 + i) = i;
  }
  for (i = 0; i < 13; i++) {
    printf("array[%d] : %d\t", i, array[i]);
    printf("*(array2 + %d) : %d\t", i, *(array2 + i));
    printf("string[%d] : %c\t", i, string[i]);
    printf("*(string + %d) : %c\n", i, *(string + i));
  }
  free(array2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    118a <main+0x4a>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <main+0x129>
lea    0xe7e(%rip),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0xa,-0x3c(%rbp)
jge    11cd <main+0x8d>
mov    -0x3c(%rbp),%ecx
movslq -0x3c(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119c <main+0x5c>
movl   $0x0,-0x3c(%rbp)
cmpl   $0xd,-0x3c(%rbp)
jge    1259 <main+0x119>
mov    -0x3c(%rbp),%esi
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
lea    0xe27(%rip),%rdi
movsbl %al,%edx
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
lea    0xe1a(%rip),%rdi
movsbl %al,%edx
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
lea    0xe15(%rip),%rdi
movsbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
mov    -0x3c(%rbp),%esi
mov    -0x48(%rbp),%rax
movslq -0x3c(%rbp),%rcx
lea    0xe0b(%rip),%rdi
movsbl (%rax,%rcx,1),%edx
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d4 <main+0x94>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%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    $0x28,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     121f <main+0xdf>
mov    %rax,%rbx
movaps 0xe95(%rip),%xmm0
movaps %xmm0,(%rsp)
movups %xmm0,(%rax)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups %xmm0,0x10(%rax)
movl   $0x8,0x20(%rsp)
movl   $0x8,0x20(%rax)
movl   $0x9,0x24(%rsp)
movl   $0x9,0x24(%rax)
xor    %eax,%eax
lea    0xe86(%rip),%r15
lea    0xeac(%rip),%r12
lea    0xeb6(%rip),%r13
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl %al,%edx
lea    0xe6d(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
movsbl (%rbx,%rbp,4),%edx
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
movsbl 0x0(%rbp,%r15,1),%r14d
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
cmp    $0xc,%rbp
je     1213 <main+0xd3>
mov    0x4(%rsp,%rbp,4),%eax
add    $0x1,%rbp
jmp    11c0 <main+0x80>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1239 <main+0xf9>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [8 x i8] c"Foobar.\00"
@.str.2 = [16 x i8] c"array[%d] : %d\09\00"
@.str.3 = [21 x i8] c"*(array2 + %d) : %d\09\00"
@.str.4 = [17 x i8] c"string[%d] : %c\09\00"
@.str.5 = [21 x i8] c"*(string + %d) : %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32* @malloc(i32 40)
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %69
12: ; preds = %0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i32 0, i32* %4
br label %13
13: ; preds = %26, %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 10
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %19
store i32 %17, i32* %20
%21 = load i32, i32* %4
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %13
29: ; preds = %13
store i32 0, i32* %4
br label %30
30: ; preds = %63, %29
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 13
br i1 %32, label %33, label %66
33: ; preds = %30
%34 = load i32, i32* %4
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = trunc i32 %38 to i8
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8 signext %39)
%41 = load i32, i32* %4
%42 = load i32*, i32** %3
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = trunc i32 %46 to i8
%48 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %41, i8 signext %47)
%49 = load i32, i32* %4
%50 = load i8*, i8** %5
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %49, i8 signext %54)
%56 = load i32, i32* %4
%57 = load i8*, i8** %5
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %56, i8 signext %61)
br label %63
63: ; preds = %33
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 1
store i32 %65, i32* %4
br label %30
66: ; preds = %30
%67 = load i32*, i32** %3
%68 = call i32 @free(i32* %67)
store i32 0, i32* %1
br label %69
69: ; preds = %66, %9
%70 = load i32, i32* %1
ret i32 %70
}

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