#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(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;
  unsigned char *h;
  void *d;
  h = (unsigned char *)malloc(N);
  d = acc_malloc(N);
  acc_map_data(h, d, N >> 1);
  if (acc_is_present(h, 1) != 1)
    abort();
  if (acc_is_present(h + (N >> 1), 1) != 0)
    abort();
  acc_unmap_data(h);
  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    $0x80,%edx
call   1070 <acc_map_data@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x1,%eax
je     11e9 <main+0x69>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%rdi
add    $0x80,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x0,%eax
je     120e <main+0x8e>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1060 <acc_unmap_data@plt>
mov    -0x28(%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   %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    %rbx,%rdi
mov    %rax,%rsi
mov    $0x80,%edx
call   1070 <acc_map_data@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
cmp    $0x1,%eax
jne    11f7 <main+0x77>
lea    0x80(%rbx),%rdi
mov    $0x1,%esi
call   1080 <acc_is_present@plt>
test   %eax,%eax
jne    11f7 <main+0x77>
mov    %rbx,%rdi
call   1060 <acc_unmap_data@plt>
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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 256, i32* %6
%9 = call i64 @malloc(i32 256)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = call i8* @acc_malloc(i32 256)
store i8* %11, i8** %8
%12 = load i8*, i8** %7
%13 = load i8*, i8** %8
%14 = call i32 @acc_map_data(i8* %12, i8* %13, i32 128)
%15 = load i8*, i8** %7
%16 = call i32 @acc_is_present(i8* %15, i32 1)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 128
%23 = call i32 @acc_is_present(i8* %22, i32 1)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %20
%28 = load i8*, i8** %7
%29 = call i32 @acc_unmap_data(i8* %28)
%30 = load i8*, i8** %8
%31 = call i32 @acc_free(i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
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 128)
%7 = tail call i32 @acc_is_present(i8* %4, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8, i8* %4, i64 128
%13 = tail call i32 @acc_is_present(i8* %12, i32 1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %11
%18 = tail call i32 @acc_unmap_data(i8* %4)
%19 = tail call i32 @acc_free(i8* %5)
%20 = tail call i32 @free(i8* %4)
ret i32 0
}