#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*/ abort();
int /*<<< orphan*/ acc_device_nvidia;
int /*<<< orphan*/ acc_free(void *);
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
void *acc_malloc(int const);
int /*<<< orphan*/ acc_memcpy_from_device(unsigned char *, void *, int const);
int /*<<< orphan*/ acc_memcpy_to_device(void *, unsigned char *, int const);
int /*<<< orphan*/ acc_shutdown(int /*<<< orphan*/);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int const);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int const);
int main(int argc, char **argv) {
  const int N = 256;
  int i;
  unsigned char *h;
  void *d;
  acc_init(acc_device_nvidia);
  h = (unsigned char *)malloc(N);
  for (i = 0; i < N; i++) {
    h[i] = i;
  }
  d = acc_malloc(N);
  acc_memcpy_to_device(d, h, N);
  memset(&h[0], 0, N);
  acc_memcpy_to_device(d, h, N << 1);
  acc_memcpy_from_device(h, d, N);
  for (i = 0; i < N; i++) {
    if (h[i] != i)
      abort();
  }
  acc_free(d);
  free(h);
  acc_shutdown(acc_device_nvidia);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x14(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   10a0 <acc_init@plt>
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    120b <main+0x6b>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e0 <main+0x40>
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x100,%edx
call   10b0 <acc_memcpy_to_device@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x200,%edx
call   10b0 <acc_memcpy_to_device@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   10c0 <acc_memcpy_from_device@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    12a2 <main+0x102>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    -0x18(%rbp),%eax
je     128f <main+0xef>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1294 <main+0xf4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1266 <main+0xc6>
mov    -0x28(%rbp),%rdi
call   1090 <acc_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1060 <acc_shutdown@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e31(%rip),%r15
mov    (%r15),%edi
call   10a0 <acc_init@plt>
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
movaps 0xe35(%rip),%xmm0
movups %xmm0,(%rax)
movaps 0xe3b(%rip),%xmm0
movups %xmm0,0x10(%rax)
movaps 0xe40(%rip),%xmm0
movups %xmm0,0x20(%rax)
movaps 0xe45(%rip),%xmm0
movups %xmm0,0x30(%rax)
movaps 0xe4a(%rip),%xmm0
movups %xmm0,0x40(%rax)
movaps 0xe4f(%rip),%xmm0
movups %xmm0,0x50(%rax)
movaps 0xe54(%rip),%xmm0
movups %xmm0,0x60(%rax)
movaps 0xe59(%rip),%xmm0
movups %xmm0,0x70(%rax)
movaps 0xe5e(%rip),%xmm0
movups %xmm0,0x80(%rax)
movaps 0xe60(%rip),%xmm0
movups %xmm0,0x90(%rax)
movaps 0xe62(%rip),%xmm0
movups %xmm0,0xa0(%rax)
movaps 0xe64(%rip),%xmm0
movups %xmm0,0xb0(%rax)
movaps 0xe66(%rip),%xmm0
movups %xmm0,0xc0(%rax)
movaps 0xe68(%rip),%xmm0
movups %xmm0,0xd0(%rax)
movaps 0xe6a(%rip),%xmm0
movups %xmm0,0xe0(%rax)
movaps 0xe6c(%rip),%xmm0
movups %xmm0,0xf0(%rax)
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   10b0 <acc_memcpy_to_device@plt>
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
call   10b0 <acc_memcpy_to_device@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x100,%edx
call   10c0 <acc_memcpy_from_device@plt>
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%eax
cmp    %rax,%rbx
jne    134c <main+0x1ac>
movzbl 0x1(%r12,%rbx,1),%ecx
lea    0x1(%rbx),%rax
cmp    %rcx,%rax
jne    134c <main+0x1ac>
movzbl 0x2(%r12,%rbx,1),%ecx
add    $0x1,%rax
cmp    %rcx,%rax
jne    134c <main+0x1ac>
movzbl 0x3(%r12,%rbx,1),%ecx
add    $0x1,%rax
cmp    %rcx,%rax
jne    134c <main+0x1ac>
add    $0x1,%rax
mov    %rax,%rbx
cmp    $0x100,%rax
jne    12e0 <main+0x140>
mov    %r14,%rdi
call   1090 <acc_free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%r15),%edi
call   1060 <acc_shutdown@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@acc_device_nvidia = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 256, i32* %6
%10 = load i32, i32* @acc_device_nvidia
%11 = call i32 @acc_init(i32 %10)
%12 = call i64 @malloc(i32 256)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
store i32 0, i32* %7
br label %14
14: ; preds = %24, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 256
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %7
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %8
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %17
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %14
27: ; preds = %14
%28 = call i8* @acc_malloc(i32 256)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = load i8*, i8** %8
%31 = call i32 @acc_memcpy_to_device(i8* %29, i8* %30, i32 256)
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 256)
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = call i32 @acc_memcpy_to_device(i8* %35, i8* %36, i32 512)
%38 = load i8*, i8** %8
%39 = load i8*, i8** %9
%40 = call i32 @acc_memcpy_from_device(i8* %38, i8* %39, i32 256)
store i32 0, i32* %7
br label %41
41: ; preds = %56, %27
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 256
br i1 %43, label %44, label %59
44: ; preds = %41
%45 = load i8*, i8** %8
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = load i32, i32* %7
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %44
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %44
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
br label %41
59: ; preds = %41
%60 = load i8*, i8** %9
%61 = call i32 @acc_free(i8* %60)
%62 = load i8*, i8** %8
%63 = call i32 @free(i8* %62)
%64 = load i32, i32* @acc_device_nvidia
%65 = call i32 @acc_shutdown(i32 %64)
ret i32 0
}

LLVM IR (-O2):
@acc_device_nvidia = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @acc_device_nvidia
%4 = tail call i32 @acc_init(i32 %3)
%5 = tail call i64 @malloc(i32 256)
%6 = inttoptr i64 %5 to i8*
%7 = inttoptr i64 %5 to <16 x i8>*
store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, <16 x i8>* %7
%8 = getelementptr inbounds i8, i8* %6, i64 16
%9 = bitcast i8* %8 to <16 x i8>*
store <16 x i8> <i8 16, i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31>, <16 x i8>* %9
%10 = getelementptr inbounds i8, i8* %6, i64 32
%11 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> <i8 32, i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47>, <16 x i8>* %11
%12 = getelementptr inbounds i8, i8* %6, i64 48
%13 = bitcast i8* %12 to <16 x i8>*
store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63>, <16 x i8>* %13
%14 = getelementptr inbounds i8, i8* %6, i64 64
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> <i8 64, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79>, <16 x i8>* %15
%16 = getelementptr inbounds i8, i8* %6, i64 80
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> <i8 80, i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95>, <16 x i8>* %17
%18 = getelementptr inbounds i8, i8* %6, i64 96
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> <i8 96, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111>, <16 x i8>* %19
%20 = getelementptr inbounds i8, i8* %6, i64 112
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> <i8 112, i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127>, <16 x i8>* %21
%22 = getelementptr inbounds i8, i8* %6, i64 128
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> <i8 -128, i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113>, <16 x i8>* %23
%24 = getelementptr inbounds i8, i8* %6, i64 144
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> <i8 -112, i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97>, <16 x i8>* %25
%26 = getelementptr inbounds i8, i8* %6, i64 160
%27 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> <i8 -96, i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81>, <16 x i8>* %27
%28 = getelementptr inbounds i8, i8* %6, i64 176
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> <i8 -80, i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65>, <16 x i8>* %29
%30 = getelementptr inbounds i8, i8* %6, i64 192
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> <i8 -64, i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49>, <16 x i8>* %31
%32 = getelementptr inbounds i8, i8* %6, i64 208
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> <i8 -48, i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33>, <16 x i8>* %33
%34 = getelementptr inbounds i8, i8* %6, i64 224
%35 = bitcast i8* %34 to <16 x i8>*
store <16 x i8> <i8 -32, i8 -31, i8 -30, i8 -29, i8 -28, i8 -27, i8 -26, i8 -25, i8 -24, i8 -23, i8 -22, i8 -21, i8 -20, i8 -19, i8 -18, i8 -17>, <16 x i8>* %35
%36 = getelementptr inbounds i8, i8* %6, i64 240
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> <i8 -16, i8 -15, i8 -14, i8 -13, i8 -12, i8 -11, i8 -10, i8 -9, i8 -8, i8 -7, i8 -6, i8 -5, i8 -4, i8 -3, i8 -2, i8 -1>, <16 x i8>* %37
%38 = tail call i8* @acc_malloc(i32 256)
%39 = tail call i32 @acc_memcpy_to_device(i8* %38, i8* %6, i32 256)
%40 = tail call i32 @memset(i8* %6, i32 0, i32 256)
%41 = tail call i32 @acc_memcpy_to_device(i8* %38, i8* %6, i32 512)
%42 = tail call i32 @acc_memcpy_from_device(i8* %6, i8* %38, i32 256)
br label %64
43: ; preds = %64
%44 = or i64 %65, 1
%45 = getelementptr inbounds i8, i8* %6, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i64
%48 = icmp eq i64 %44, %47
br i1 %48, label %49, label %70
49: ; preds = %43
%50 = or i64 %65, 2
%51 = getelementptr inbounds i8, i8* %6, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i64
%54 = icmp eq i64 %50, %53
br i1 %54, label %55, label %70
55: ; preds = %49
%56 = or i64 %65, 3
%57 = getelementptr inbounds i8, i8* %6, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i64
%60 = icmp eq i64 %56, %59
br i1 %60, label %61, label %70
61: ; preds = %55
%62 = add nuw nsw i64 %65, 4
%63 = icmp eq i64 %62, 256
br i1 %63, label %72, label %64
64: ; preds = %61, %2
%65 = phi i64 [ 0, %2 ], [ %62, %61 ]
%66 = getelementptr inbounds i8, i8* %6, i64 %65
%67 = load i8, i8* %66
%68 = zext i8 %67 to i64
%69 = icmp eq i64 %65, %68
br i1 %69, label %43, label %70
70: ; preds = %55, %49, %43, %64
%71 = tail call i32 (...) @abort()
unreachable
72: ; preds = %61
%73 = tail call i32 @acc_free(i8* %38)
%74 = tail call i32 @free(i8* %6)
%75 = load i32, i32* @acc_device_nvidia
%76 = tail call i32 @acc_shutdown(i32 %75)
ret i32 0
}