#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_free(void *);
void *acc_malloc(size_t const);
int /*<<< orphan*/ acc_map_data(unsigned char *, void *, size_t const);
int /*<<< orphan*/ acc_memcpy_from_device(unsigned char *, void *,
                                          size_t const);
int /*<<< orphan*/ acc_memcpy_to_device(void *, unsigned char *, size_t const);
int /*<<< orphan*/ acc_unmap_data(unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(size_t const);
int /*<<< orphan*/ memset(unsigned char *, int const, size_t const);
int main() {
  const int c0 = 9;
  const int c1 = 40;
  const int c2 = 47;
  const size_t N = 256;
  unsigned char *h = (unsigned char *)malloc(N);
  void *d = acc_malloc(N);
  memset(h, c0, N);
  acc_memcpy_to_device(d, h, N);
  memset(h, c1, N);
  acc_map_data(h, d, N);
  for (size_t i = 0; i < N; ++i)
    if (h[i] != c1)
      abort();
  acc_memcpy_from_device(h, d, N);
  for (size_t i = 0; i < N; ++i)
    if (h[i] != c0)
      abort();
  memset(h, c2, N);
  acc_unmap_data(h);
  for (size_t i = 0; i < N; ++i)
    if (h[i] != c2)
      abort();
  acc_memcpy_from_device(h, d, N);
  for (size_t i = 0; i < N; ++i)
    if (h[i] != c0)
      abort();
  acc_free(d);
  free(h);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x9,-0x8(%rbp)
movl   $0x28,-0xc(%rbp)
movl   $0x2f,-0x10(%rbp)
movq   $0x100,-0x18(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x9,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x100,%edx
call   10b0 <acc_memcpy_to_device@plt>
mov    -0x20(%rbp),%rdi
mov    $0x28,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   1070 <acc_map_data@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x100,-0x30(%rbp)
jae    127a <main+0xda>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
je     1264 <main+0xc4>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1269 <main+0xc9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    123a <main+0x9a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   10c0 <acc_memcpy_from_device@plt>
movq   $0x0,-0x38(%rbp)
cmpq   $0x100,-0x38(%rbp)
jae    12d4 <main+0x134>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     12be <main+0x11e>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    12c3 <main+0x123>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1294 <main+0xf4>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
call   1060 <acc_unmap_data@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x100,-0x40(%rbp)
jae    1338 <main+0x198>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1322 <main+0x182>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1327 <main+0x187>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12f8 <main+0x158>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   10c0 <acc_memcpy_from_device@plt>
movq   $0x0,-0x48(%rbp)
cmpq   $0x100,-0x48(%rbp)
jae    1392 <main+0x1f2>
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     137c <main+0x1dc>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1381 <main+0x1e1>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1352 <main+0x1b2>
mov    -0x28(%rbp),%rdi
call   10a0 <acc_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,%r14
mov    $0x100,%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1080 <memset@plt>
mov    $0x100,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <acc_memcpy_to_device@plt>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    $0x28,%esi
call   1080 <memset@plt>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <acc_map_data@plt>
mov    $0x3,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x28,-0x3(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x28,-0x2(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x28,-0x1(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x28,(%rbx,%rax,1)
jne    1341 <main+0x1a1>
add    $0x4,%rax
cmp    $0x103,%rax
jne    1210 <main+0x70>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <acc_memcpy_from_device@plt>
mov    $0x3,%eax
nopl   0x0(%rax)
cmpb   $0x9,-0x3(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,-0x2(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,-0x1(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,(%rbx,%rax,1)
jne    1341 <main+0x1a1>
add    $0x4,%rax
cmp    $0x103,%rax
jne    1260 <main+0xc0>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1060 <acc_unmap_data@plt>
mov    $0x3,%eax
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x2f,-0x3(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x2f,-0x2(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x2f,-0x1(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x2f,(%rbx,%rax,1)
jne    1341 <main+0x1a1>
add    $0x4,%rax
cmp    $0x103,%rax
jne    12c0 <main+0x120>
mov    $0x100,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <acc_memcpy_from_device@plt>
mov    $0x3,%eax
nopl   0x0(%rax)
cmpb   $0x9,-0x3(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,-0x2(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,-0x1(%rbx,%rax,1)
jne    1341 <main+0x1a1>
cmpb   $0x9,(%rbx,%rax,1)
jne    1341 <main+0x1a1>
add    $0x4,%rax
cmp    $0x103,%rax
jne    1300 <main+0x160>
mov    %r14,%rdi
call   10a0 <acc_free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %1
store i32 9, i32* %2
store i32 40, i32* %3
store i32 47, i32* %4
store i64 256, i64* %5
%12 = call i64 @malloc(i64 256)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = call i8* @acc_malloc(i64 256)
store i8* %14, i8** %7
%15 = load i8*, i8** %6
%16 = call i32 @memset(i8* %15, i32 9, i64 256)
%17 = load i8*, i8** %7
%18 = load i8*, i8** %6
%19 = call i32 @acc_memcpy_to_device(i8* %17, i8* %18, i64 256)
%20 = load i8*, i8** %6
%21 = call i32 @memset(i8* %20, i32 40, i64 256)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call i32 @acc_map_data(i8* %22, i8* %23, i64 256)
store i64 0, i64* %8
br label %25
25: ; preds = %38, %0
%26 = load i64, i64* %8
%27 = icmp ult i64 %26, 256
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i64, i64* %8
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp ne i32 %33, 40
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %28
br label %38
38: ; preds = %37
%39 = load i64, i64* %8
%40 = add i64 %39, 1
store i64 %40, i64* %8
br label %25
41: ; preds = %25
%42 = load i8*, i8** %6
%43 = load i8*, i8** %7
%44 = call i32 @acc_memcpy_from_device(i8* %42, i8* %43, i64 256)
store i64 0, i64* %9
br label %45
45: ; preds = %58, %41
%46 = load i64, i64* %9
%47 = icmp ult i64 %46, 256
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = load i64, i64* %9
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = icmp ne i32 %53, 9
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 (...) @abort()
unreachable
57: ; preds = %48
br label %58
58: ; preds = %57
%59 = load i64, i64* %9
%60 = add i64 %59, 1
store i64 %60, i64* %9
br label %45
61: ; preds = %45
%62 = load i8*, i8** %6
%63 = call i32 @memset(i8* %62, i32 47, i64 256)
%64 = load i8*, i8** %6
%65 = call i32 @acc_unmap_data(i8* %64)
store i64 0, i64* %10
br label %66
66: ; preds = %79, %61
%67 = load i64, i64* %10
%68 = icmp ult i64 %67, 256
br i1 %68, label %69, label %82
69: ; preds = %66
%70 = load i8*, i8** %6
%71 = load i64, i64* %10
%72 = getelementptr inbounds i8, i8* %70, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = icmp ne i32 %74, 47
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = call i32 (...) @abort()
unreachable
78: ; preds = %69
br label %79
79: ; preds = %78
%80 = load i64, i64* %10
%81 = add i64 %80, 1
store i64 %81, i64* %10
br label %66
82: ; preds = %66
%83 = load i8*, i8** %6
%84 = load i8*, i8** %7
%85 = call i32 @acc_memcpy_from_device(i8* %83, i8* %84, i64 256)
store i64 0, i64* %11
br label %86
86: ; preds = %99, %82
%87 = load i64, i64* %11
%88 = icmp ult i64 %87, 256
br i1 %88, label %89, label %102
89: ; preds = %86
%90 = load i8*, i8** %6
%91 = load i64, i64* %11
%92 = getelementptr inbounds i8, i8* %90, i64 %91
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = icmp ne i32 %94, 9
br i1 %95, label %96, label %98
96: ; preds = %89
%97 = call i32 (...) @abort()
unreachable
98: ; preds = %89
br label %99
99: ; preds = %98
%100 = load i64, i64* %11
%101 = add i64 %100, 1
store i64 %101, i64* %11
br label %86
102: ; preds = %86
%103 = load i8*, i8** %7
%104 = call i32 @acc_free(i8* %103)
%105 = load i8*, i8** %6
%106 = call i32 @free(i8* %105)
ret i32 0
}

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