#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 *);
int acc_is_present(unsigned char *, int);
void *acc_malloc(int const);
int /*<<< orphan*/ acc_map_data(void *, void *, int);
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;
  unsigned char *h;
  int i;
  void *d;
  h = (unsigned char *)malloc(N);
  d = acc_malloc(N);
  for (i = 0; i < N; i++) {
    acc_map_data((void *)((uintptr_t)h + (uintptr_t)i),
                 (void *)((uintptr_t)d + (uintptr_t)i), 1);
  }
  for (i = 0; i < N; i++) {
    if (acc_is_present(h + 1, 1) != 1)
      abort();
  }
  for (i = 0; i < N; i++) {
    acc_unmap_data(h + i);
  }
  for (i = 0; i < N; i++) {
    if (acc_is_present(h + 1, 1) != 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,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    11fb <main+0x7b>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1070 <acc_map_data@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c0 <main+0x40>
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    1244 <main+0xc4>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x1,%eax
je     1231 <main+0xb1>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    1236 <main+0xb6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1202 <main+0x82>
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    1276 <main+0xf6>
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
call   1060 <acc_unmap_data@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    124b <main+0xcb>
movl   $0x0,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    12bf <main+0x13f>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x0,%eax
je     12ac <main+0x12c>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    12b1 <main+0x131>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127d <main+0xfd>
mov    -0x30(%rbp),%rdi
call   10a0 <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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    $0x100,%edi
call   1050 <acc_malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r15,%rbx,1),%rdi
lea    (%r14,%rbx,1),%rsi
mov    $0x1,%edx
call   1070 <acc_map_data@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    11b0 <main+0x30>
lea    0x1(%r15),%rbx
mov    $0x100,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x1,%eax
jne    1253 <main+0xd3>
add    $0xffffffff,%ebp
jne    11e0 <main+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax)
lea    (%r15,%rbp,1),%rdi
call   1060 <acc_unmap_data@plt>
add    $0x1,%rbp
cmp    $0x100,%rbp
jne    1200 <main+0x80>
mov    $0x100,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
test   %eax,%eax
jne    1253 <main+0xd3>
add    $0xffffffff,%ebp
jne    1220 <main+0xa0>
mov    %r14,%rdi
call   10a0 <acc_free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 i8*
%8 = alloca i32
%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** %7
%12 = call i8* @acc_malloc(i32 256)
store i8* %12, i8** %9
store i32 0, i32* %8
br label %13
13: ; preds = %30, %2
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 256
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = ptrtoint i8* %17 to i64
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = add i64 %18, %20
%22 = inttoptr i64 %21 to i8*
%23 = load i8*, i8** %9
%24 = ptrtoint i8* %23 to i64
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = add i64 %24, %26
%28 = inttoptr i64 %27 to i8*
%29 = call i32 @acc_map_data(i8* %22, i8* %28, i32 1)
br label %30
30: ; preds = %16
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %13
33: ; preds = %13
store i32 0, i32* %8
br label %34
34: ; preds = %45, %33
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 256
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @acc_is_present(i8* %39, i32 1)
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 (...) @abort()
unreachable
44: ; preds = %37
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %34
48: ; preds = %34
store i32 0, i32* %8
br label %49
49: ; preds = %58, %48
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 256
br i1 %51, label %52, label %61
52: ; preds = %49
%53 = load i8*, i8** %7
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = call i32 @acc_unmap_data(i8* %56)
br label %58
58: ; preds = %52
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
br label %49
61: ; preds = %49
store i32 0, i32* %8
br label %62
62: ; preds = %73, %61
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 256
br i1 %64, label %65, label %76
65: ; preds = %62
%66 = load i8*, i8** %7
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = call i32 @acc_is_present(i8* %67, i32 1)
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = call i32 (...) @abort()
unreachable
72: ; preds = %65
br label %73
73: ; preds = %72
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %62
76: ; preds = %62
%77 = load i8*, i8** %9
%78 = call i32 @acc_free(i8* %77)
%79 = load i8*, i8** %7
%80 = call i32 @free(i8* %79)
ret i32 0
}

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