#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();
void *acc_deviceptr(unsigned char *);
int /*<<< orphan*/ acc_free(void *);
void *acc_hostptr(void *);
void *acc_malloc(int const);
int /*<<< orphan*/ acc_map_data(unsigned char *, void *, int const);
int /*<<< orphan*/ acc_unmap_data(unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int const);
int main(int argc, char **argv) {
  const int N = 256;
  int i;
  unsigned char *h;
  void *d;
  h = (unsigned char *)malloc(N);
  d = acc_malloc(N);
  acc_map_data(h, d, N);
  for (i = 0; i < N; i++) {
    if (acc_hostptr((void *)((uintptr_t)d + (uintptr_t)i)) !=
        (void *)((uintptr_t)h + (uintptr_t)i))
      abort();
  }
  for (i = 0; i < N; i++) {
    if (acc_deviceptr((void *)((uintptr_t)h + (uintptr_t)i)) !=
        (void *)((uintptr_t)d + (uintptr_t)i))
      abort();
  }
  acc_unmap_data(h);
  for (i = 0; i < N; i++) {
    if (acc_hostptr((void *)((uintptr_t)d + (uintptr_t)i)) != 0)
      abort();
  }
  for (i = 0; i < N; i++) {
    if (acc_deviceptr(h + i) != 0)
      abort();
  }
  acc_free(d);
  free(h);
  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    $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    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   1080 <acc_map_data@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    122d <main+0x9d>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1070 <acc_hostptr@plt>
mov    -0x20(%rbp),%rcx
movslq -0x18(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     121a <main+0x8a>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    121f <main+0x8f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <main+0x52>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    127f <main+0xef>
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   10a0 <acc_deviceptr@plt>
mov    -0x28(%rbp),%rcx
movslq -0x18(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     126c <main+0xdc>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1271 <main+0xe1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1234 <main+0xa4>
mov    -0x20(%rbp),%rdi
call   1060 <acc_unmap_data@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    12d0 <main+0x140>
mov    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1070 <acc_hostptr@plt>
cmp    $0x0,%rax
je     12bd <main+0x12d>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    12c2 <main+0x132>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    128f <main+0xff>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    1318 <main+0x188>
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   10a0 <acc_deviceptr@plt>
cmp    $0x0,%rax
je     1305 <main+0x175>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    130a <main+0x17a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12d7 <main+0x147>
mov    -0x28(%rbp),%rdi
call   10b0 <acc_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1080 <acc_map_data@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rdi
call   1070 <acc_hostptr@plt>
lea    (%r14,%rbx,1),%rcx
cmp    %rcx,%rax
jne    1283 <main+0xf3>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    11d0 <main+0x40>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r14,%rbx,1),%rdi
call   10a0 <acc_deviceptr@plt>
lea    (%r15,%rbx,1),%rcx
cmp    %rcx,%rax
jne    1283 <main+0xf3>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1200 <main+0x70>
mov    %r14,%rdi
call   1060 <acc_unmap_data@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%r15,%rbx,1),%rdi
call   1070 <acc_hostptr@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1230 <main+0xa0>
xor    %ebx,%ebx
nopl   (%rax)
lea    (%r14,%rbx,1),%rdi
call   10a0 <acc_deviceptr@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1250 <main+0xc0>
mov    %r15,%rdi
call   10b0 <acc_free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1040 <abort@plt>

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

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 256)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i8* @acc_malloc(i32 256)
%6 = tail call i32 @acc_map_data(i8* %4, i8* %5, i32 256)
%7 = ptrtoint i8* %5 to i64
br label %11
8: ; preds = %11
%9 = add nuw nsw i64 %12, 1
%10 = icmp eq i64 %9, 256
br i1 %10, label %24, label %11
11: ; preds = %2, %8
%12 = phi i64 [ 0, %2 ], [ %9, %8 ]
%13 = add i64 %12, %7
%14 = inttoptr i64 %13 to i8*
%15 = tail call i8* @acc_hostptr(i8* %14)
%16 = add i64 %3, %12
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i8* %15, %17
br i1 %18, label %8, label %19
19: ; preds = %11
%20 = tail call i32 (...) @abort()
unreachable
21: ; preds = %24
%22 = add nuw nsw i64 %25, 1
%23 = icmp eq i64 %22, 256
br i1 %23, label %34, label %24
24: ; preds = %8, %21
%25 = phi i64 [ %22, %21 ], [ 0, %8 ]
%26 = add i64 %3, %25
%27 = inttoptr i64 %26 to i8*
%28 = tail call i8* @acc_deviceptr(i8* %27)
%29 = add i64 %25, %7
%30 = inttoptr i64 %29 to i8*
%31 = icmp eq i8* %28, %30
br i1 %31, label %21, label %32
32: ; preds = %24
%33 = tail call i32 (...) @abort()
unreachable
34: ; preds = %21
%35 = tail call i32 @acc_unmap_data(i8* %4)
br label %39
36: ; preds = %39
%37 = add nuw nsw i64 %40, 1
%38 = icmp eq i64 %37, 256
br i1 %38, label %50, label %39
39: ; preds = %34, %36
%40 = phi i64 [ 0, %34 ], [ %37, %36 ]
%41 = add i64 %40, %7
%42 = inttoptr i64 %41 to i8*
%43 = tail call i8* @acc_hostptr(i8* %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %36, label %45
45: ; preds = %39
%46 = tail call i32 (...) @abort()
unreachable
47: ; preds = %50
%48 = add nuw nsw i64 %51, 1
%49 = icmp eq i64 %48, 256
br i1 %49, label %57, label %50
50: ; preds = %36, %47
%51 = phi i64 [ %48, %47 ], [ 0, %36 ]
%52 = getelementptr inbounds i8, i8* %4, i64 %51
%53 = tail call i8* @acc_deviceptr(i8* %52)
%54 = icmp eq i8* %53, null
br i1 %54, label %47, label %55
55: ; preds = %50
%56 = tail call i32 (...) @abort()
unreachable
57: ; preds = %47
%58 = tail call i32 @acc_free(i8* %5)
%59 = tail call i32 @free(i8* %4)
ret i32 0
}