#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 MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
int /*<<< orphan*/ mic_alloc(double *, int, int, int);
int /*<<< orphan*/ mic_free(double *, int, int, int);
int /*<<< orphan*/ mic_get_max_threads(int, int);
int /*<<< orphan*/ mic_pull_free(double *, int, int, int);
int /*<<< orphan*/ mic_push(double *, int, int, int);
scalar_t__ mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(double *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ voodoo(double *, double *, double *, int, int, int);
int main(int argc, char **argv) {
  int device = 0;
  int iter = 3;
  int nelem = 50000000;
  int offload = argc > 1 ? atoi(argv[1]) : 1;
  void *handle;
  char *error;
  printf("Initializing device(%d)... offload(%d)?\n", device, offload);
  mic_get_max_threads(device, offload);
  printf("Allocating on host...\n");
  double *a = (double *)mmap(0, nelem * sizeof(double), PROT_READ | PROT_WRITE,
                             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  double *b = (double *)mmap(0, nelem * sizeof(double), PROT_READ | PROT_WRITE,
                             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  double *c = (double *)mmap(0, nelem * sizeof(double), PROT_READ | PROT_WRITE,
                             MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  printf("Initializing on host...\n");
  for (int i = 0; i < nelem; ++i) {
    a[i] = i;
    b[i] = i;
  }
  printf("Allocating on device...\n");
  mic_alloc(a, nelem, device, offload);
  mic_alloc(b, nelem, device, offload);
  mic_alloc(c, nelem, device, offload);
  printf("Copying to device...\n");
  mic_push(a, nelem, device, offload);
  mic_push(a, nelem, device, offload);
  printf("Doing some work on device...\n");
  for (int i = 0; i < iter; ++i) {
    voodoo(a, b, c, nelem, device, offload);
  }
  printf("Retrieving data from and deallocating data on device...\n");
  mic_free(a, nelem, device, offload);
  mic_free(b, nelem, device, offload);
  mic_pull_free(c, nelem, device, offload);
  printf("Bla bla...\n");
  printf("c[nelem/2] = %f\n", c[nelem / 2]);
  printf("Deallocating on host...");
  munmap(a, nelem * sizeof(double));
  munmap(b, nelem * sizeof(double));
  munmap(c, nelem * sizeof(double));
  printf("Bye!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
movl   $0x2faf080,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ea <main+0x4a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x54(%rbp)
jmp    11f7 <main+0x57>
mov    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f7 <main+0x57>
mov    -0x54(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1070 <mic_get_max_threads@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
mov    0x2d8c(%rip),%rax
or     (%rax),%edx
mov    0x2d7b(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8a(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x38(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
mov    0x2d49(%rip),%rax
or     (%rax),%edx
mov    0x2d38(%rip),%rax
mov    (%rax),%ecx
mov    0x2d47(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x40(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
mov    0x2d06(%rip),%rax
or     (%rax),%edx
mov    0x2cf5(%rip),%rax
mov    (%rax),%ecx
mov    0x2d04(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x48(%rbp)
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1346 <main+0x1a6>
cvtsi2sdl -0x4c(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x4c(%rbp),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1308 <main+0x168>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <mic_alloc@plt>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <mic_alloc@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <mic_alloc@plt>
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1060 <mic_push@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1060 <mic_push@plt>
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1407 <main+0x267>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x20(%rbp),%r9d
call   10a0 <voodoo@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    13d1 <main+0x231>
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   10c0 <mic_free@plt>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   10c0 <mic_free@plt>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1080 <mic_pull_free@plt>
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xc6a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1090 <munmap@plt>
mov    -0x40(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1090 <munmap@plt>
mov    -0x48(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1090 <munmap@plt>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r14d
cmp    $0x2,%edi
jl     11d2 <main+0x22>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
lea    0xe77(%rip),%rdi
xor    %esi,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %r14d,%esi
call   1080 <mic_get_max_threads@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df6(%rip),%r12
mov    0x2dc7(%rip),%rbp
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    0x2db1(%rip),%r15
mov    0x2dc2(%rip),%r13
mov    0x0(%r13),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x17d78400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    %rax,%rbx
mov    0x0(%r13),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x17d78400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    %rax,%rbp
mov    0x0(%r13),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x17d78400,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%r15
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
lea    0x17d78400(%rbp),%rax
cmp    %rax,%rbx
jae    1325 <main+0x175>
mov    %rbx,%rax
add    $0x17d78400,%rax
cmp    %rax,%rbp
jae    1325 <main+0x175>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
movsd  %xmm0,0x0(%rbp,%rax,8)
lea    0x1(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x8(%rbx,%rax,8)
movsd  %xmm0,0x8(%rbp,%rax,8)
lea    0x2(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x10(%rbx,%rax,8)
movsd  %xmm0,0x10(%rbp,%rax,8)
lea    0x3(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x18(%rbx,%rax,8)
movsd  %xmm0,0x18(%rbp,%rax,8)
add    $0x4,%rax
cmp    $0x2faf080,%rax
jne    12c0 <main+0x110>
jmp    13bf <main+0x20f>
movdqa 0xcd3(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xcd6(%rip),%xmm1
movdqa 0xcde(%rip),%xmm2
movdqa 0xce6(%rip),%xmm3
movdqa 0xcee(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm0,%xmm5
cvtdq2pd %xmm0,%xmm6
paddd  %xmm1,%xmm5
cvtdq2pd %xmm5,%xmm5
movups %xmm6,-0x30(%rbx,%rax,8)
movups %xmm5,-0x20(%rbx,%rax,8)
movups %xmm6,-0x30(%rbp,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm2,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm3,%xmm7
cvtdq2pd %xmm6,%xmm6
cvtdq2pd %xmm7,%xmm7
movups %xmm5,-0x20(%rbp,%rax,8)
movups %xmm6,-0x10(%rbx,%rax,8)
movups %xmm7,(%rbx,%rax,8)
movups %xmm6,-0x10(%rbp,%rax,8)
movups %xmm7,0x0(%rbp,%rax,8)
paddd  %xmm4,%xmm0
add    $0x8,%rax
cmp    $0x2faf086,%rax
jne    1360 <main+0x1b0>
lea    0xd0a(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1040 <mic_alloc@plt>
mov    %rbp,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1040 <mic_alloc@plt>
mov    %r15,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1040 <mic_alloc@plt>
lea    0xce0(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1070 <mic_push@plt>
mov    %rbx,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1070 <mic_push@plt>
lea    0xcc5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    $0x2faf080,%ecx
xor    %r8d,%r8d
mov    %r14d,%r9d
call   10b0 <voodoo@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    $0x2faf080,%ecx
xor    %r8d,%r8d
mov    %r14d,%r9d
call   10b0 <voodoo@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    $0x2faf080,%ecx
xor    %r8d,%r8d
mov    %r14d,%r9d
call   10b0 <voodoo@plt>
lea    0xc8b(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   10d0 <mic_free@plt>
mov    %rbp,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   10d0 <mic_free@plt>
mov    %r15,%rdi
mov    $0x2faf080,%esi
xor    %edx,%edx
mov    %r14d,%ecx
call   1090 <mic_pull_free@plt>
lea    0xc81(%rip),%rdi
call   1030 <puts@plt>
movsd  0xbebc200(%r15),%xmm0
eb 0b
lea    0xb93(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xb96(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x17d78400,%esi
call   10a0 <munmap@plt>
mov    %rbp,%rdi
mov    $0x17d78400,%esi
call   10a0 <munmap@plt>
mov    %r15,%rdi
mov    $0x17d78400,%esi
call   10a0 <munmap@plt>
lea    0xc34(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Initializing device(%d)... offload(%d)?\0A\00"
@.str.1 = [23 x i8] c"Allocating on host...\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.2 = [25 x i8] c"Initializing on host...\0A\00"
@.str.3 = [25 x i8] c"Allocating on device...\0A\00"
@.str.4 = [22 x i8] c"Copying to device...\0A\00"
@.str.5 = [30 x i8] c"Doing some work on device...\0A\00"
@.str.6 = [57 x i8] c"Retrieving data from and deallocating data on device...\0A\00"
@.str.7 = [12 x i8] c"Bla bla...\0A\00"
@.str.8 = [17 x i8] c"c[nelem/2] = %f\0A\00"
@.str.9 = [24 x i8] c"Deallocating on host...\00"
@.str.10 = [6 x i8] c"Bye!\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
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 3, i32* %7
store i32 50000000, i32* %8
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
br label %25
24: ; preds = %2
br label %25
25: ; preds = %24, %19
%26 = phi i32 [ %23, %19 ], [ 1, %24 ]
store i32 %26, i32* %9
%27 = load i32, i32* %6
%28 = load i32, i32* %9
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28)
%30 = load i32, i32* %6
%31 = load i32, i32* %9
%32 = call i32 @mic_get_max_threads(i32 %30, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 8
%37 = trunc i64 %36 to i32
%38 = load i32, i32* @PROT_READ
%39 = load i32, i32* @PROT_WRITE
%40 = or i32 %38, %39
%41 = load i32, i32* @MAP_PRIVATE
%42 = load i32, i32* @MAP_ANONYMOUS
%43 = or i32 %41, %42
%44 = call i64 @mmap(i32 0, i32 %37, i32 %40, i32 %43, i32 -1, i32 0)
%45 = inttoptr i64 %44 to double*
store double* %45, double** %12
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 8
%49 = trunc i64 %48 to i32
%50 = load i32, i32* @PROT_READ
%51 = load i32, i32* @PROT_WRITE
%52 = or i32 %50, %51
%53 = load i32, i32* @MAP_PRIVATE
%54 = load i32, i32* @MAP_ANONYMOUS
%55 = or i32 %53, %54
%56 = call i64 @mmap(i32 0, i32 %49, i32 %52, i32 %55, i32 -1, i32 0)
%57 = inttoptr i64 %56 to double*
store double* %57, double** %13
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 8
%61 = trunc i64 %60 to i32
%62 = load i32, i32* @PROT_READ
%63 = load i32, i32* @PROT_WRITE
%64 = or i32 %62, %63
%65 = load i32, i32* @MAP_PRIVATE
%66 = load i32, i32* @MAP_ANONYMOUS
%67 = or i32 %65, %66
%68 = call i64 @mmap(i32 0, i32 %61, i32 %64, i32 %67, i32 -1, i32 0)
%69 = inttoptr i64 %68 to double*
store double* %69, double** %14
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %15
br label %71
71: ; preds = %88, %25
%72 = load i32, i32* %15
%73 = load i32, i32* %8
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %91
75: ; preds = %71
%76 = load i32, i32* %15
%77 = sitofp i32 %76 to double
%78 = load double*, double** %12
%79 = load i32, i32* %15
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double, double* %78, i64 %80
store double %77, double* %81
%82 = load i32, i32* %15
%83 = sitofp i32 %82 to double
%84 = load double*, double** %13
%85 = load i32, i32* %15
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
store double %83, double* %87
br label %88
88: ; preds = %75
%89 = load i32, i32* %15
%90 = add nsw i32 %89, 1
store i32 %90, i32* %15
br label %71
91: ; preds = %71
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%93 = load double*, double** %12
%94 = load i32, i32* %8
%95 = load i32, i32* %6
%96 = load i32, i32* %9
%97 = call i32 @mic_alloc(double* %93, i32 %94, i32 %95, i32 %96)
%98 = load double*, double** %13
%99 = load i32, i32* %8
%100 = load i32, i32* %6
%101 = load i32, i32* %9
%102 = call i32 @mic_alloc(double* %98, i32 %99, i32 %100, i32 %101)
%103 = load double*, double** %14
%104 = load i32, i32* %8
%105 = load i32, i32* %6
%106 = load i32, i32* %9
%107 = call i32 @mic_alloc(double* %103, i32 %104, i32 %105, i32 %106)
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%109 = load double*, double** %12
%110 = load i32, i32* %8
%111 = load i32, i32* %6
%112 = load i32, i32* %9
%113 = call i32 @mic_push(double* %109, i32 %110, i32 %111, i32 %112)
%114 = load double*, double** %12
%115 = load i32, i32* %8
%116 = load i32, i32* %6
%117 = load i32, i32* %9
%118 = call i32 @mic_push(double* %114, i32 %115, i32 %116, i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %16
br label %120
120: ; preds = %132, %91
%121 = load i32, i32* %16
%122 = load i32, i32* %7
%123 = icmp slt i32 %121, %122
br i1 %123, label %124, label %135
124: ; preds = %120
%125 = load double*, double** %12
%126 = load double*, double** %13
%127 = load double*, double** %14
%128 = load i32, i32* %8
%129 = load i32, i32* %6
%130 = load i32, i32* %9
%131 = call i32 @voodoo(double* %125, double* %126, double* %127, i32 %128, i32 %129, i32 %130)
br label %132
132: ; preds = %124
%133 = load i32, i32* %16
%134 = add nsw i32 %133, 1
store i32 %134, i32* %16
br label %120
135: ; preds = %120
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0))
%137 = load double*, double** %12
%138 = load i32, i32* %8
%139 = load i32, i32* %6
%140 = load i32, i32* %9
%141 = call i32 @mic_free(double* %137, i32 %138, i32 %139, i32 %140)
%142 = load double*, double** %13
%143 = load i32, i32* %8
%144 = load i32, i32* %6
%145 = load i32, i32* %9
%146 = call i32 @mic_free(double* %142, i32 %143, i32 %144, i32 %145)
%147 = load double*, double** %14
%148 = load i32, i32* %8
%149 = load i32, i32* %6
%150 = load i32, i32* %9
%151 = call i32 @mic_pull_free(double* %147, i32 %148, i32 %149, i32 %150)
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%153 = load double*, double** %14
%154 = load i32, i32* %8
%155 = sdiv i32 %154, 2
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds double, double* %153, i64 %156
%158 = load double, double* %157
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), double %158)
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%161 = load double*, double** %12
%162 = load i32, i32* %8
%163 = sext i32 %162 to i64
%164 = mul i64 %163, 8
%165 = trunc i64 %164 to i32
%166 = call i32 @munmap(double* %161, i32 %165)
%167 = load double*, double** %13
%168 = load i32, i32* %8
%169 = sext i32 %168 to i64
%170 = mul i64 %169, 8
%171 = trunc i64 %170 to i32
%172 = call i32 @munmap(double* %167, i32 %171)
%173 = load double*, double** %14
%174 = load i32, i32* %8
%175 = sext i32 %174 to i64
%176 = mul i64 %175, 8
%177 = trunc i64 %176 to i32
%178 = call i32 @munmap(double* %173, i32 %177)
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Initializing device(%d)... offload(%d)?\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.8 = [17 x i8] c"c[nelem/2] = %f\0A\00"
@.str.9 = [24 x i8] c"Deallocating on host...\00"
@str = [22 x i8] c"Allocating on host...\00"
@str.11 = [24 x i8] c"Initializing on host...\00"
@str.12 = [24 x i8] c"Allocating on device...\00"
@str.13 = [21 x i8] c"Copying to device...\00"
@str.14 = [29 x i8] c"Doing some work on device...\00"
@str.15 = [56 x i8] c"Retrieving data from and deallocating data on device...\00"
@str.16 = [11 x i8] c"Bla bla...\00"
@str.17 = [5 x i8] c"Bye!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 1, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 0, i32 %9)
%11 = tail call i32 @mic_get_max_threads(i32 0, i32 %9)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @PROT_WRITE
%15 = or i32 %14, %13
%16 = load i32, i32* @MAP_PRIVATE
%17 = load i32, i32* @MAP_ANONYMOUS
%18 = or i32 %17, %16
%19 = tail call i64 @mmap(i32 0, i32 400000000, i32 %15, i32 %18, i32 -1, i32 0)
%20 = inttoptr i64 %19 to double*
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @PROT_WRITE
%23 = or i32 %22, %21
%24 = load i32, i32* @MAP_PRIVATE
%25 = load i32, i32* @MAP_ANONYMOUS
%26 = or i32 %25, %24
%27 = tail call i64 @mmap(i32 0, i32 400000000, i32 %23, i32 %26, i32 -1, i32 0)
%28 = inttoptr i64 %27 to double*
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @PROT_WRITE
%31 = or i32 %30, %29
%32 = load i32, i32* @MAP_PRIVATE
%33 = load i32, i32* @MAP_ANONYMOUS
%34 = or i32 %33, %32
%35 = tail call i64 @mmap(i32 0, i32 400000000, i32 %31, i32 %34, i32 -1, i32 0)
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%37 = inttoptr i64 %27 to i8*
%38 = inttoptr i64 %19 to i8*
%39 = getelementptr double, double* %20, i64 50000000
%40 = bitcast double* %39 to i8*
%41 = getelementptr double, double* %28, i64 50000000
%42 = bitcast double* %41 to i8*
%43 = icmp ult i8* %38, %42
%44 = icmp ult i8* %37, %40
%45 = and i1 %43, %44
br i1 %45, label %102, label %46
46: ; preds = %8, %46
%47 = phi i64 [ %73, %46 ], [ 0, %8 ]
%48 = phi <2 x i32> [ %74, %46 ], [ <i32 0, i32 1>, %8 ]
%49 = add <2 x i32> %48, <i32 2, i32 2>
%50 = sitofp <2 x i32> %48 to <2 x double>
%51 = sitofp <2 x i32> %49 to <2 x double>
%52 = getelementptr inbounds double, double* %20, i64 %47
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> %50, <2 x double>* %53
%54 = getelementptr inbounds double, double* %52, i64 2
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %51, <2 x double>* %55
%56 = getelementptr inbounds double, double* %28, i64 %47
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %50, <2 x double>* %57
%58 = getelementptr inbounds double, double* %56, i64 2
%59 = bitcast double* %58 to <2 x double>*
store <2 x double> %51, <2 x double>* %59
%60 = or i64 %47, 4
%61 = add <2 x i32> %48, <i32 4, i32 4>
%62 = add <2 x i32> %48, <i32 6, i32 6>
%63 = sitofp <2 x i32> %61 to <2 x double>
%64 = sitofp <2 x i32> %62 to <2 x double>
%65 = getelementptr inbounds double, double* %20, i64 %60
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %63, <2 x double>* %66
%67 = getelementptr inbounds double, double* %65, i64 2
%68 = bitcast double* %67 to <2 x double>*
store <2 x double> %64, <2 x double>* %68
%69 = getelementptr inbounds double, double* %28, i64 %60
%70 = bitcast double* %69 to <2 x double>*
store <2 x double> %63, <2 x double>* %70
%71 = getelementptr inbounds double, double* %69, i64 2
%72 = bitcast double* %71 to <2 x double>*
store <2 x double> %64, <2 x double>* %72
%73 = add nuw nsw i64 %47, 8
%74 = add <2 x i32> %48, <i32 8, i32 8>
%75 = icmp eq i64 %73, 50000000
br i1 %75, label %76, label %46
76: ; preds = %46, %102
%77 = inttoptr i64 %35 to double*
%78 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
%79 = tail call i32 @mic_alloc(double* %20, i32 50000000, i32 0, i32 %9)
%80 = tail call i32 @mic_alloc(double* %28, i32 50000000, i32 0, i32 %9)
%81 = tail call i32 @mic_alloc(double* %77, i32 50000000, i32 0, i32 %9)
%82 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
%83 = tail call i32 @mic_push(double* %20, i32 50000000, i32 0, i32 %9)
%84 = tail call i32 @mic_push(double* %20, i32 50000000, i32 0, i32 %9)
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0))
%86 = tail call i32 @voodoo(double* %20, double* %28, double* %77, i32 50000000, i32 0, i32 %9)
%87 = tail call i32 @voodoo(double* %20, double* %28, double* %77, i32 50000000, i32 0, i32 %9)
%88 = tail call i32 @voodoo(double* %20, double* %28, double* %77, i32 50000000, i32 0, i32 %9)
%89 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.15, i64 0, i64 0))
%90 = tail call i32 @mic_free(double* %20, i32 50000000, i32 0, i32 %9)
%91 = tail call i32 @mic_free(double* %28, i32 50000000, i32 0, i32 %9)
%92 = tail call i32 @mic_pull_free(double* %77, i32 50000000, i32 0, i32 %9)
%93 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.16, i64 0, i64 0))
%94 = getelementptr inbounds double, double* %77, i64 25000000
%95 = load double, double* %94
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), double %95)
%97 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%98 = tail call i32 @munmap(double* %20, i32 400000000)
%99 = tail call i32 @munmap(double* %28, i32 400000000)
%100 = tail call i32 @munmap(double* %77, i32 400000000)
%101 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.17, i64 0, i64 0))
ret i32 0
102: ; preds = %8, %102
%103 = phi i64 [ %123, %102 ], [ 0, %8 ]
%104 = trunc i64 %103 to i32
%105 = sitofp i32 %104 to double
%106 = getelementptr inbounds double, double* %20, i64 %103
store double %105, double* %106
%107 = getelementptr inbounds double, double* %28, i64 %103
store double %105, double* %107
%108 = or i64 %103, 1
%109 = trunc i64 %108 to i32
%110 = sitofp i32 %109 to double
%111 = getelementptr inbounds double, double* %20, i64 %108
store double %110, double* %111
%112 = getelementptr inbounds double, double* %28, i64 %108
store double %110, double* %112
%113 = or i64 %103, 2
%114 = trunc i64 %113 to i32
%115 = sitofp i32 %114 to double
%116 = getelementptr inbounds double, double* %20, i64 %113
store double %115, double* %116
%117 = getelementptr inbounds double, double* %28, i64 %113
store double %115, double* %117
%118 = or i64 %103, 3
%119 = trunc i64 %118 to i32
%120 = sitofp i32 %119 to double
%121 = getelementptr inbounds double, double* %20, i64 %118
store double %120, double* %121
%122 = getelementptr inbounds double, double* %28, i64 %118
store double %120, double* %122
%123 = add nuw nsw i64 %103, 4
%124 = icmp eq i64 %123, 50000000
br i1 %124, label %76, label %102
}