#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*/ free(int **);
int **malloc(int);
int main() {
  int a = 3;
  int b = 2;
  int c = 8;
  int **arr = malloc(sizeof(int *) * 3);
  arr[0] = &a;
  arr[1] = &b;
  arr[2] = &c;
  int sum = 0;
  for (int i = 0; i < 3; i++) {
    sum += *(arr[i]);
  }
  free(arr);
  return sum;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
movl   $0x8,-0x10(%rbp)
mov    $0x18,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
lea    -0x8(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
lea    -0xc(%rbp),%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
lea    -0x10(%rbp),%rcx
mov    %rcx,0x10(%rax)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    11af <main+0x8f>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1183 <main+0x63>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    $0x18,%edi
call   1040 <malloc@plt>
lea    0x14(%rsp),%rcx
mov    %rcx,(%rax)
lea    0x10(%rsp),%rcx
mov    %rcx,0x8(%rax)
lea    0xc(%rsp),%rcx
mov    %rcx,0x10(%rax)
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0xd,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 3, i32* %2
store i32 2, i32* %3
store i32 8, i32* %4
%8 = call i32** @malloc(i32 24)
store i32** %8, i32*** %5
%9 = load i32**, i32*** %5
%10 = getelementptr inbounds i32*, i32** %9, i64 0
store i32* %2, i32** %10
%11 = load i32**, i32*** %5
%12 = getelementptr inbounds i32*, i32** %11, i64 1
store i32* %3, i32** %12
%13 = load i32**, i32*** %5
%14 = getelementptr inbounds i32*, i32** %13, i64 2
store i32* %4, i32** %14
store i32 0, i32* %6
store i32 0, i32* %7
br label %15
15: ; preds = %27, %0
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32**, i32*** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
%23 = load i32*, i32** %22
%24 = load i32, i32* %23
%25 = load i32, i32* %6
%26 = add nsw i32 %25, %24
store i32 %26, i32* %6
br label %27
27: ; preds = %18
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %15
30: ; preds = %15
%31 = load i32**, i32*** %5
%32 = call i32 @free(i32** %31)
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32** @malloc(i32 24)
store i32* %1, i32** %7
%8 = getelementptr inbounds i32*, i32** %7, i64 1
store i32* %2, i32** %8
%9 = getelementptr inbounds i32*, i32** %7, i64 2
store i32* %3, i32** %9
%10 = call i32 @free(i32** %7)
ret i32 13
}