#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ DMA_BUF_SYNC_END;
int /*<<< orphan*/ DMA_BUF_SYNC_START;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ close_handle(int, int /*<<< orphan*/);
int dmabuf_heap_alloc(int, int, int /*<<< orphan*/, int *);
int dmabuf_heap_open(char *);
int dmabuf_sync(int, int /*<<< orphan*/);
int import_vgem_fd(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(void *, int, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open_vgem();
int /*<<< orphan*/ printf(char *);
int test_alloc_and_import(char *heap_name) {
  int heap_fd = -1, dmabuf_fd = -1, importer_fd = -1;
  uint32_t handle = 0;
  void *p = NULL;
  int ret;
  heap_fd = dmabuf_heap_open(heap_name);
  if (heap_fd < 0)
    return -1;
  printf("  Testing allocation and importing:  ");
  ret = dmabuf_heap_alloc(heap_fd, (1024 * 1024), 0, &dmabuf_fd);
  if (ret) {
    printf("FAIL (Allocation Failed!)\n");
    ret = -1;
    goto out;
  }
  p = mmap(NULL, (1024 * 1024), PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd,
           0);
  if (p == MAP_FAILED) {
    printf("FAIL (mmap() failed)\n");
    ret = -1;
    goto out;
  }
  dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
  memset(p, 1, (1024 * 1024) / 2);
  memset((char *)p + (1024 * 1024) / 2, 0, (1024 * 1024) / 2);
  dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
  importer_fd = open_vgem();
  if (importer_fd < 0) {
    ret = importer_fd;
    printf("(Could not open vgem - skipping):  ");
  } else {
    ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle);
    if (ret < 0) {
      printf("FAIL (Failed to import buffer)\n");
      goto out;
    }
  }
  ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
  if (ret < 0) {
    printf("FAIL (DMA_BUF_SYNC_START failed!)\n");
    goto out;
  }
  memset(p, 0xff, (1024 * 1024));
  ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
  if (ret < 0) {
    printf("FAIL (DMA_BUF_SYNC_END failed!)\n");
    goto out;
  }
  close_handle(importer_fd, handle);
  ret = 0;
  printf(" OK\n");
out:
  if (p)
    munmap(p, (1024 * 1024));
  if (importer_fd >= 0)
    close(importer_fd);
  if (dmabuf_fd >= 0)
    close(dmabuf_fd);
  if (heap_fd >= 0)
    close(heap_fd);
  return ret;
}


x86 assembly (clang, -O0):
<test_alloc_and_import>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dmabuf_heap_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1202 <test_alloc_and_import+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1433 <test_alloc_and_import+0x283>
lea    0xdf7(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x100000,%esi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
call   10c0 <dmabuf_heap_alloc@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1246 <test_alloc_and_import+0x96>
lea    0xdf1(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    13de <test_alloc_and_import+0x22e>
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    0x2d72(%rip),%rax
or     (%rax),%edx
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100000,%esi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
jne    12a6 <test_alloc_and_import+0xf6>
lea    0xdac(%rip),%rdi
call   1070 <printf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    13de <test_alloc_and_import+0x22e>
mov    -0x18(%rbp),%edi
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
call   1080 <dmabuf_sync@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x80000,%edx
call   1090 <memset@plt>
mov    -0x28(%rbp),%rdi
add    $0x80000,%rdi
xor    %esi,%esi
mov    $0x80000,%edx
call   1090 <memset@plt>
mov    -0x18(%rbp),%edi
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
call   1080 <dmabuf_sync@plt>
mov    $0x0,%al
call   10b0 <open_vgem@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    131d <test_alloc_and_import+0x16d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    0xd44(%rip),%rdi
call   1070 <printf@plt>
jmp    134f <test_alloc_and_import+0x19f>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1050 <import_vgem_fd@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    134a <test_alloc_and_import+0x19a>
lea    0xd3b(%rip),%rdi
call   1070 <printf@plt>
jmp    13de <test_alloc_and_import+0x22e>
jmp    134f <test_alloc_and_import+0x19f>
mov    -0x18(%rbp),%edi
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
call   1080 <dmabuf_sync@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    137e <test_alloc_and_import+0x1ce>
lea    0xd27(%rip),%rdi
call   1070 <printf@plt>
jmp    13de <test_alloc_and_import+0x22e>
mov    -0x28(%rbp),%rdi
mov    $0xff,%esi
mov    $0x100000,%edx
call   1090 <memset@plt>
mov    -0x18(%rbp),%edi
mov    0x2c3d(%rip),%rax
mov    (%rax),%esi
call   1080 <dmabuf_sync@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    13c0 <test_alloc_and_import+0x210>
lea    0xd08(%rip),%rdi
call   1070 <printf@plt>
jmp    13de <test_alloc_and_import+0x22e>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <close_handle@plt>
movl   $0x0,-0x2c(%rbp)
lea    0xd06(%rip),%rdi
call   1070 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     13f7 <test_alloc_and_import+0x247>
mov    -0x28(%rbp),%rdi
mov    $0x100000,%esi
call   10d0 <munmap@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     1409 <test_alloc_and_import+0x259>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jl     141b <test_alloc_and_import+0x26b>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jl     142d <test_alloc_and_import+0x27d>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_alloc_and_import>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0xffffffff,(%rsp)
movl   $0x0,0x4(%rsp)
call   1040 <dmabuf_heap_open@plt>
test   %eax,%eax
js     121c <test_alloc_and_import+0x5c>
mov    %eax,%ebx
lea    0xe14(%rip),%rdi
call   1080 <printf@plt>
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x100000,%esi
xor    %edx,%edx
call   10d0 <dmabuf_heap_alloc@plt>
test   %eax,%eax
je     1226 <test_alloc_and_import+0x66>
lea    0xeb7(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebp
jmp    137c <test_alloc_and_import+0x1bc>
mov    $0xffffffff,%ebp
jmp    138f <test_alloc_and_import+0x1cf>
mov    0x2dcb(%rip),%rax
mov    0x2d94(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2da9(%rip),%rax
mov    (%rax),%ecx
mov    (%rsp),%r8d
xor    %edi,%edi
mov    $0x100000,%esi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,%r14
mov    0x2d5a(%rip),%rax
cmp    (%rax),%r14
je     12db <test_alloc_and_import+0x11b>
mov    (%rsp),%edi
mov    0x2d53(%rip),%r12
mov    (%r12),%esi
call   1090 <dmabuf_sync@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x80000,%edx
call   10a0 <memset@plt>
lea    0x80000(%r14),%rdi
xor    %esi,%esi
mov    $0x80000,%edx
call   10a0 <memset@plt>
mov    (%rsp),%edi
mov    0x2d33(%rip),%r13
mov    0x0(%r13),%esi
call   1090 <dmabuf_sync@plt>
xor    %eax,%eax
call   10c0 <open_vgem@plt>
mov    %eax,%r15d
test   %eax,%eax
js     12ef <test_alloc_and_import+0x12f>
mov    (%rsp),%esi
lea    0x4(%rsp),%rdx
mov    %r15d,%edi
call   1060 <import_vgem_fd@plt>
test   %eax,%eax
jns    12fb <test_alloc_and_import+0x13b>
mov    %eax,%ebp
lea    0xdb7(%rip),%rdi
jmp    1358 <test_alloc_and_import+0x198>
mov    $0xffffffff,%r15d
lea    0xdc7(%rip),%rdi
mov    $0xffffffff,%ebp
jmp    1358 <test_alloc_and_import+0x198>
lea    0xd30(%rip),%rdi
call   1080 <printf@plt>
mov    (%rsp),%edi
mov    (%r12),%esi
call   1090 <dmabuf_sync@plt>
test   %eax,%eax
js     1344 <test_alloc_and_import+0x184>
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x100000,%edx
call   10a0 <memset@plt>
mov    (%rsp),%edi
mov    0x0(%r13),%esi
call   1090 <dmabuf_sync@plt>
test   %eax,%eax
js     134f <test_alloc_and_import+0x18f>
mov    0x4(%rsp),%esi
mov    %r15d,%edi
call   1030 <close_handle@plt>
xor    %ebp,%ebp
lea    0xd08(%rip),%rdi
jmp    1358 <test_alloc_and_import+0x198>
mov    %eax,%ebp
lea    0xd21(%rip),%rdi
jmp    1358 <test_alloc_and_import+0x198>
mov    %eax,%ebp
lea    0xcf6(%rip),%rdi
call   1050 <puts@plt>
test   %r14,%r14
je     136f <test_alloc_and_import+0x1af>
mov    %r14,%rdi
mov    $0x100000,%esi
call   10e0 <munmap@plt>
test   %r15d,%r15d
js     137c <test_alloc_and_import+0x1bc>
mov    %r15d,%edi
call   10b0 <close@plt>
mov    (%rsp),%edi
test   %edi,%edi
js     1388 <test_alloc_and_import+0x1c8>
call   10b0 <close@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c" Testing allocation and importing: \00"
@.str.1 = [27 x i8] c"FAIL (Allocation Failed!)\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [22 x i8] c"FAIL (mmap() failed)\0A\00"
@DMA_BUF_SYNC_START = global i32 0
@DMA_BUF_SYNC_END = global i32 0
@.str.3 = [36 x i8] c"(Could not open vgem - skipping): \00"
@.str.4 = [32 x i8] c"FAIL (Failed to import buffer)\0A\00"
@.str.5 = [35 x i8] c"FAIL (DMA_BUF_SYNC_START failed!)\0A\00"
@.str.6 = [33 x i8] c"FAIL (DMA_BUF_SYNC_END failed!)\0A\00"
@.str.7 = [5 x i8] c" OK\0A\00"
define i32 @test_alloc_and_import(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 -1, i32* %5
store i32 -1, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
%10 = load i8*, i8** %3
%11 = call i32 @dmabuf_heap_open(i8* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %111
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = call i32 @dmabuf_heap_alloc(i32 %17, i32 1048576, i32 0, i32* %5)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %85
23: ; preds = %15
%24 = load i32, i32* @PROT_READ
%25 = load i32, i32* @PROT_WRITE
%26 = or i32 %24, %25
%27 = load i32, i32* @MAP_SHARED
%28 = load i32, i32* %5
%29 = call i8* @mmap(i32* null, i32 1048576, i32 %26, i32 %27, i32 %28, i32 0)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = load i8*, i8** @MAP_FAILED
%32 = icmp eq i8* %30, %31
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %9
br label %85
35: ; preds = %23
%36 = load i32, i32* %5
%37 = load i32, i32* @DMA_BUF_SYNC_START
%38 = call i32 @dmabuf_sync(i32 %36, i32 %37)
%39 = load i8*, i8** %8
%40 = call i32 @memset(i8* %39, i32 1, i32 524288)
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 524288
%43 = call i32 @memset(i8* %42, i32 0, i32 524288)
%44 = load i32, i32* %5
%45 = load i32, i32* @DMA_BUF_SYNC_END
%46 = call i32 @dmabuf_sync(i32 %44, i32 %45)
%47 = call i32 (...) @open_vgem()
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %35
%51 = load i32, i32* %6
store i32 %51, i32* %9
%52 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %62
53: ; preds = %35
%54 = load i32, i32* %6
%55 = load i32, i32* %5
%56 = call i32 @import_vgem_fd(i32 %54, i32 %55, i32* %7)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %85
61: ; preds = %53
br label %62
62: ; preds = %61, %50
%63 = load i32, i32* %5
%64 = load i32, i32* @DMA_BUF_SYNC_START
%65 = call i32 @dmabuf_sync(i32 %63, i32 %64)
store i32 %65, i32* %9
%66 = load i32, i32* %9
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %85
70: ; preds = %62
%71 = load i8*, i8** %8
%72 = call i32 @memset(i8* %71, i32 255, i32 1048576)
%73 = load i32, i32* %5
%74 = load i32, i32* @DMA_BUF_SYNC_END
%75 = call i32 @dmabuf_sync(i32 %73, i32 %74)
store i32 %75, i32* %9
%76 = load i32, i32* %9
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %70
%79 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %85
80: ; preds = %70
%81 = load i32, i32* %6
%82 = load i32, i32* %7
%83 = call i32 @close_handle(i32 %81, i32 %82)
store i32 0, i32* %9
%84 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %85
85: ; preds = %80, %78, %68, %59, %33, %21
%86 = load i8*, i8** %8
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %8
%90 = call i32 @munmap(i8* %89, i32 1048576)
br label %91
91: ; preds = %88, %85
%92 = load i32, i32* %6
%93 = icmp sge i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = load i32, i32* %6
%96 = call i32 @close(i32 %95)
br label %97
97: ; preds = %94, %91
%98 = load i32, i32* %5
%99 = icmp sge i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = load i32, i32* %5
%102 = call i32 @close(i32 %101)
br label %103
103: ; preds = %100, %97
%104 = load i32, i32* %4
%105 = icmp sge i32 %104, 0
br i1 %105, label %106, label %109
106: ; preds = %103
%107 = load i32, i32* %4
%108 = call i32 @close(i32 %107)
br label %109
109: ; preds = %106, %103
%110 = load i32, i32* %9
store i32 %110, i32* %2
br label %111
111: ; preds = %109, %14
%112 = load i32, i32* %2
ret i32 %112
}

LLVM IR (-O2):
@.str = [38 x i8] c" Testing allocation and importing: \00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@DMA_BUF_SYNC_START = global i32 0
@DMA_BUF_SYNC_END = global i32 0
@.str.3 = [36 x i8] c"(Could not open vgem - skipping): \00"
@str = [4 x i8] c" OK\00"
@str.8 = [32 x i8] c"FAIL (DMA_BUF_SYNC_END failed!)\00"
@str.9 = [34 x i8] c"FAIL (DMA_BUF_SYNC_START failed!)\00"
@str.10 = [31 x i8] c"FAIL (Failed to import buffer)\00"
@str.11 = [21 x i8] c"FAIL (mmap() failed)\00"
@str.12 = [26 x i8] c"FAIL (Allocation Failed!)\00"
define i32 @test_alloc_and_import(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 @dmabuf_heap_open(i8* %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %75, label %8
8: ; preds = %1
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @dmabuf_heap_alloc(i32 %6, i32 1048576, i32 0, i32* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
br label %67
14: ; preds = %8
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @PROT_WRITE
%17 = or i32 %16, %15
%18 = load i32, i32* @MAP_SHARED
%19 = load i32, i32* %2
%20 = call i8* @mmap(i32* null, i32 1048576, i32 %17, i32 %18, i32 %19, i32 0)
%21 = load i8*, i8** @MAP_FAILED
%22 = icmp eq i8* %20, %21
br i1 %22, label %55, label %23
23: ; preds = %14
%24 = load i32, i32* %2
%25 = load i32, i32* @DMA_BUF_SYNC_START
%26 = call i32 @dmabuf_sync(i32 %24, i32 %25)
%27 = call i32 @memset(i8* %20, i32 1, i32 524288)
%28 = getelementptr inbounds i8, i8* %20, i64 524288
%29 = call i32 @memset(i8* %28, i32 0, i32 524288)
%30 = load i32, i32* %2
%31 = load i32, i32* @DMA_BUF_SYNC_END
%32 = call i32 @dmabuf_sync(i32 %30, i32 %31)
%33 = call i32 (...) @open_vgem()
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %23
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %41
37: ; preds = %23
%38 = load i32, i32* %2
%39 = call i32 @import_vgem_fd(i32 %33, i32 %38, i32* %3)
%40 = icmp slt i32 %39, 0
br i1 %40, label %55, label %41
41: ; preds = %37, %35
%42 = load i32, i32* %2
%43 = load i32, i32* @DMA_BUF_SYNC_START
%44 = call i32 @dmabuf_sync(i32 %42, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %55, label %46
46: ; preds = %41
%47 = call i32 @memset(i8* %20, i32 255, i32 1048576)
%48 = load i32, i32* %2
%49 = load i32, i32* @DMA_BUF_SYNC_END
%50 = call i32 @dmabuf_sync(i32 %48, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %46
%53 = load i32, i32* %3
%54 = call i32 @close_handle(i32 %33, i32 %53)
br label %55
55: ; preds = %46, %41, %37, %14, %52
%56 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0), %52 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0), %14 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0), %37 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.9, i64 0, i64 0), %41 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.8, i64 0, i64 0), %46 ]
%57 = phi i32 [ %33, %52 ], [ -1, %14 ], [ %33, %37 ], [ %33, %41 ], [ %33, %46 ]
%58 = phi i32 [ 0, %52 ], [ -1, %14 ], [ %39, %37 ], [ %44, %41 ], [ %50, %46 ]
%59 = call i32 @puts(i8* dereferenceable(1) %56)
%60 = icmp eq i8* %20, null
br i1 %60, label %63, label %61
61: ; preds = %55
%62 = call i32 @munmap(i8* %20, i32 1048576)
br label %63
63: ; preds = %61, %55
%64 = icmp sgt i32 %57, -1
br i1 %64, label %65, label %67
65: ; preds = %63
%66 = call i32 @close(i32 %57)
br label %67
67: ; preds = %12, %65, %63
%68 = phi i32 [ -1, %12 ], [ %58, %65 ], [ %58, %63 ]
%69 = load i32, i32* %2
%70 = icmp sgt i32 %69, -1
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @close(i32 %69)
br label %73
73: ; preds = %67, %71
%74 = call i32 @close(i32 %6)
br label %75
75: ; preds = %1, %73
%76 = phi i32 [ %68, %73 ], [ -1, %1 ]
ret i32 %76
}