#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 */
struct nvmap_framebuffer {
  int dummy;
};
struct nvmap {
  int dummy;
};
struct nvhost_gr2d {
  int dummy;
};
struct nvhost_ctrl {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ nvhost_ctrl_close(struct nvhost_ctrl *);
struct nvhost_ctrl *nvhost_ctrl_open();
int nvhost_gr2d_clear(struct nvhost_gr2d *, struct nvmap_framebuffer *, float,
                      float, float, float);
int /*<<< orphan*/ nvhost_gr2d_close(struct nvhost_gr2d *);
struct nvhost_gr2d *nvhost_gr2d_open(struct nvmap *, struct nvhost_ctrl *);
int /*<<< orphan*/ nvmap_close(struct nvmap *);
struct nvmap_framebuffer *nvmap_framebuffer_create(struct nvmap *, unsigned int,
                                                   unsigned int, int);
int /*<<< orphan*/ nvmap_framebuffer_free(struct nvmap_framebuffer *);
int /*<<< orphan*/ nvmap_framebuffer_save(struct nvmap_framebuffer *, char *);
struct nvmap *nvmap_open();
int main(int argc, char *argv[]) {
  struct nvmap_framebuffer *fb;
  unsigned int width, height;
  struct nvhost_gr2d *gr2d;
  struct nvhost_ctrl *ctrl;
  struct nvmap *nvmap;
  int err;
  width = height = 32;
  nvmap = nvmap_open();
  if (!nvmap) {
    return 1;
  }
  ctrl = nvhost_ctrl_open();
  if (!ctrl) {
    return 1;
  }
  fb = nvmap_framebuffer_create(nvmap, width, height, 32);
  if (!fb) {
    return 1;
  }
  gr2d = nvhost_gr2d_open(nvmap, ctrl);
  if (!gr2d) {
    return 1;
  }
  err = nvhost_gr2d_clear(gr2d, fb, 1.0f, 0.0f, 1.0f, 1.0f);
  if (err < 0) {
    return 1;
  }
  nvmap_framebuffer_save(fb, "test.png");
  nvmap_framebuffer_free(fb);
  nvhost_gr2d_close(gr2d);
  nvhost_ctrl_close(ctrl);
  nvmap_close(nvmap);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20,-0x20(%rbp)
movl   $0x20,-0x1c(%rbp)
mov    $0x0,%al
call   10b0 <nvmap_open@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e6 <main+0x46>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    $0x0,%al
call   1090 <nvhost_ctrl_open@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1208 <main+0x68>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    $0x20,%ecx
call   1040 <nvmap_framebuffer_create@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1237 <main+0x97>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <nvhost_gr2d_open@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125f <main+0xbf>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movss  0xd91(%rip),%xmm3
xorps  %xmm1,%xmm1
movaps %xmm3,%xmm0
movaps %xmm3,%xmm2
call   1060 <nvhost_gr2d_clear@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1296 <main+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    -0x18(%rbp),%rdi
lea    0xd63(%rip),%rsi
call   1050 <nvmap_framebuffer_save@plt>
mov    -0x18(%rbp),%rdi
call   1080 <nvmap_framebuffer_free@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <nvhost_gr2d_close@plt>
mov    -0x30(%rbp),%rdi
call   1070 <nvhost_ctrl_close@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <nvmap_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   10b0 <nvmap_open@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1256 <main+0xb6>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <nvhost_ctrl_open@plt>
test   %rax,%rax
je     1256 <main+0xb6>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
mov    $0x20,%ecx
call   1040 <nvmap_framebuffer_create@plt>
test   %rax,%rax
je     1256 <main+0xb6>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <nvhost_gr2d_open@plt>
test   %rax,%rax
je     1256 <main+0xb6>
mov    %rax,%r12
movss  0xdf3(%rip),%xmm0
xorps  %xmm1,%xmm1
mov    %rax,%rdi
mov    %r15,%rsi
movaps %xmm0,%xmm2
movaps %xmm0,%xmm3
call   1060 <nvhost_gr2d_clear@plt>
test   %eax,%eax
js     1256 <main+0xb6>
lea    0xdd8(%rip),%rsi
mov    %r15,%rdi
call   1050 <nvmap_framebuffer_save@plt>
mov    %r15,%rdi
call   1080 <nvmap_framebuffer_free@plt>
mov    %r12,%rdi
call   10a0 <nvhost_gr2d_close@plt>
mov    %r14,%rdi
call   1070 <nvhost_ctrl_close@plt>
mov    %rbx,%rdi
call   10c0 <nvmap_close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nvmap_framebuffer = type { i32 }
%struct.nvhost_gr2d = type { i32 }
%struct.nvhost_ctrl = type { i32 }
%struct.nvmap = type { i32 }
@.str = [9 x i8] c"test.png\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.nvmap_framebuffer*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.nvhost_gr2d*
%10 = alloca %struct.nvhost_ctrl*
%11 = alloca %struct.nvmap*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 32, i32* %8
store i32 32, i32* %7
%13 = call %struct.nvmap* (...) @nvmap_open()
store %struct.nvmap* %13, %struct.nvmap** %11
%14 = load %struct.nvmap*, %struct.nvmap** %11
%15 = icmp ne %struct.nvmap* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 1, i32* %3
br label %55
17: ; preds = %2
%18 = call %struct.nvhost_ctrl* (...) @nvhost_ctrl_open()
store %struct.nvhost_ctrl* %18, %struct.nvhost_ctrl** %10
%19 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %10
%20 = icmp ne %struct.nvhost_ctrl* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 1, i32* %3
br label %55
22: ; preds = %17
%23 = load %struct.nvmap*, %struct.nvmap** %11
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call %struct.nvmap_framebuffer* @nvmap_framebuffer_create(%struct.nvmap* %23, i32 %24, i32 %25, i32 32)
store %struct.nvmap_framebuffer* %26, %struct.nvmap_framebuffer** %6
%27 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%28 = icmp ne %struct.nvmap_framebuffer* %27, null
br i1 %28, label %30, label %29
29: ; preds = %22
store i32 1, i32* %3
br label %55
30: ; preds = %22
%31 = load %struct.nvmap*, %struct.nvmap** %11
%32 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %10
%33 = call %struct.nvhost_gr2d* @nvhost_gr2d_open(%struct.nvmap* %31, %struct.nvhost_ctrl* %32)
store %struct.nvhost_gr2d* %33, %struct.nvhost_gr2d** %9
%34 = load %struct.nvhost_gr2d*, %struct.nvhost_gr2d** %9
%35 = icmp ne %struct.nvhost_gr2d* %34, null
br i1 %35, label %37, label %36
36: ; preds = %30
store i32 1, i32* %3
br label %55
37: ; preds = %30
%38 = load %struct.nvhost_gr2d*, %struct.nvhost_gr2d** %9
%39 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%40 = call i32 @nvhost_gr2d_clear(%struct.nvhost_gr2d* %38, %struct.nvmap_framebuffer* %39, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00)
store i32 %40, i32* %12
%41 = load i32, i32* %12
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
store i32 1, i32* %3
br label %55
44: ; preds = %37
%45 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%46 = call i32 @nvmap_framebuffer_save(%struct.nvmap_framebuffer* %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%47 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%48 = call i32 @nvmap_framebuffer_free(%struct.nvmap_framebuffer* %47)
%49 = load %struct.nvhost_gr2d*, %struct.nvhost_gr2d** %9
%50 = call i32 @nvhost_gr2d_close(%struct.nvhost_gr2d* %49)
%51 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %10
%52 = call i32 @nvhost_ctrl_close(%struct.nvhost_ctrl* %51)
%53 = load %struct.nvmap*, %struct.nvmap** %11
%54 = call i32 @nvmap_close(%struct.nvmap* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %44, %43, %36, %29, %21, %16
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.nvmap = type { i32 }
%struct.nvhost_ctrl = type { i32 }
%struct.nvmap_framebuffer = type { i32 }
%struct.nvhost_gr2d = type { i32 }
@.str = [9 x i8] c"test.png\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call %struct.nvmap* (...) @nvmap_open()
%4 = icmp eq %struct.nvmap* %3, null
br i1 %4, label %23, label %5
5: ; preds = %2
%6 = tail call %struct.nvhost_ctrl* (...) @nvhost_ctrl_open()
%7 = icmp eq %struct.nvhost_ctrl* %6, null
br i1 %7, label %23, label %8
8: ; preds = %5
%9 = tail call %struct.nvmap_framebuffer* @nvmap_framebuffer_create(%struct.nvmap* %3, i32 32, i32 32, i32 32)
%10 = icmp eq %struct.nvmap_framebuffer* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = tail call %struct.nvhost_gr2d* @nvhost_gr2d_open(%struct.nvmap* %3, %struct.nvhost_ctrl* %6)
%13 = icmp eq %struct.nvhost_gr2d* %12, null
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = tail call i32 @nvhost_gr2d_clear(%struct.nvhost_gr2d* %12, %struct.nvmap_framebuffer* %9, float 1.000000e+00, float 0.000000e+00, float 1.000000e+00, float 1.000000e+00)
%16 = icmp slt i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = tail call i32 @nvmap_framebuffer_save(%struct.nvmap_framebuffer* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @nvmap_framebuffer_free(%struct.nvmap_framebuffer* %9)
%20 = tail call i32 @nvhost_gr2d_close(%struct.nvhost_gr2d* %12)
%21 = tail call i32 @nvhost_ctrl_close(%struct.nvhost_ctrl* %6)
%22 = tail call i32 @nvmap_close(%struct.nvmap* %3)
br label %23
23: ; preds = %14, %11, %8, %5, %2, %17
%24 = phi i32 [ 0, %17 ], [ 1, %2 ], [ 1, %5 ], [ 1, %8 ], [ 1, %11 ], [ 1, %14 ]
ret i32 %24
}