#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_gr3d {
  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);
struct nvhost_gr2d *nvhost_gr2d_open(struct nvmap *, struct nvhost_ctrl *);
int /*<<< orphan*/ nvhost_gr3d_close(struct nvhost_gr3d *);
struct nvhost_gr3d *nvhost_gr3d_open(struct nvmap *, struct nvhost_ctrl *);
int nvhost_gr3d_triangle(struct nvhost_gr3d *, struct nvmap_framebuffer *);
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_gr3d *gr3d;
  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;
  }
  gr3d = nvhost_gr3d_open(nvmap, ctrl);
  if (!gr3d) {
    return 1;
  }
  err = nvhost_gr2d_clear(gr2d, fb, 0.0f, 0.0f, 0.0f, 1.0f);
  if (err < 0) {
    return 1;
  }
  err = nvhost_gr3d_triangle(gr3d, fb);
  if (err < 0) {
    return 1;
  }
  nvmap_framebuffer_save(fb, "test.png");
  nvmap_framebuffer_free(fb);
  nvhost_gr3d_close(gr3d);
  nvhost_ctrl_close(ctrl);
  nvmap_close(nvmap);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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   10d0 <nvmap_open@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1206 <main+0x46>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    $0x0,%al
call   10c0 <nvhost_ctrl_open@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1228 <main+0x68>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x40(%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    1257 <main+0x97>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <nvhost_gr2d_open@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127f <main+0xbf>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <nvhost_gr3d_open@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a7 <main+0xe7>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xorps  %xmm2,%xmm2
movss  0xd46(%rip),%xmm3
movaps %xmm2,%xmm0
movaps %xmm2,%xmm1
call   1070 <nvhost_gr2d_clear@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12de <main+0x11e>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <nvhost_gr3d_triangle@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1304 <main+0x144>
movl   $0x1,-0x4(%rbp)
jmp    133f <main+0x17f>
mov    -0x18(%rbp),%rdi
lea    0xcf5(%rip),%rsi
call   1050 <nvmap_framebuffer_save@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <nvmap_framebuffer_free@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <nvhost_gr3d_close@plt>
mov    -0x38(%rbp),%rdi
call   1090 <nvhost_ctrl_close@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <nvmap_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10d0 <nvmap_open@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     129f <main+0xdf>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <nvhost_ctrl_open@plt>
test   %rax,%rax
je     129f <main+0xdf>
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     129f <main+0xdf>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <nvhost_gr2d_open@plt>
test   %rax,%rax
je     129f <main+0xdf>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <nvhost_gr3d_open@plt>
test   %rax,%rax
je     129f <main+0xdf>
mov    %rax,%r12
movss  0xdb9(%rip),%xmm3
xorps  %xmm0,%xmm0
xorps  %xmm1,%xmm1
xorps  %xmm2,%xmm2
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <nvhost_gr2d_clear@plt>
test   %eax,%eax
js     129f <main+0xdf>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <nvhost_gr3d_triangle@plt>
test   %eax,%eax
js     129f <main+0xdf>
lea    0xd8f(%rip),%rsi
mov    %r15,%rdi
call   1050 <nvmap_framebuffer_save@plt>
mov    %r15,%rdi
call   10b0 <nvmap_framebuffer_free@plt>
mov    %r12,%rdi
call   10a0 <nvhost_gr3d_close@plt>
mov    %r14,%rdi
call   1090 <nvhost_ctrl_close@plt>
mov    %rbx,%rdi
call   10e0 <nvmap_close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nvmap_framebuffer = type { i32 }
%struct.nvhost_gr2d = type { i32 }
%struct.nvhost_gr3d = 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_gr3d*
%11 = alloca %struct.nvhost_ctrl*
%12 = alloca %struct.nvmap*
%13 = 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
%14 = call %struct.nvmap* (...) @nvmap_open()
store %struct.nvmap* %14, %struct.nvmap** %12
%15 = load %struct.nvmap*, %struct.nvmap** %12
%16 = icmp ne %struct.nvmap* %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
store i32 1, i32* %3
br label %70
18: ; preds = %2
%19 = call %struct.nvhost_ctrl* (...) @nvhost_ctrl_open()
store %struct.nvhost_ctrl* %19, %struct.nvhost_ctrl** %11
%20 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %11
%21 = icmp ne %struct.nvhost_ctrl* %20, null
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 1, i32* %3
br label %70
23: ; preds = %18
%24 = load %struct.nvmap*, %struct.nvmap** %12
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call %struct.nvmap_framebuffer* @nvmap_framebuffer_create(%struct.nvmap* %24, i32 %25, i32 %26, i32 32)
store %struct.nvmap_framebuffer* %27, %struct.nvmap_framebuffer** %6
%28 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%29 = icmp ne %struct.nvmap_framebuffer* %28, null
br i1 %29, label %31, label %30
30: ; preds = %23
store i32 1, i32* %3
br label %70
31: ; preds = %23
%32 = load %struct.nvmap*, %struct.nvmap** %12
%33 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %11
%34 = call %struct.nvhost_gr2d* @nvhost_gr2d_open(%struct.nvmap* %32, %struct.nvhost_ctrl* %33)
store %struct.nvhost_gr2d* %34, %struct.nvhost_gr2d** %9
%35 = load %struct.nvhost_gr2d*, %struct.nvhost_gr2d** %9
%36 = icmp ne %struct.nvhost_gr2d* %35, null
br i1 %36, label %38, label %37
37: ; preds = %31
store i32 1, i32* %3
br label %70
38: ; preds = %31
%39 = load %struct.nvmap*, %struct.nvmap** %12
%40 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %11
%41 = call %struct.nvhost_gr3d* @nvhost_gr3d_open(%struct.nvmap* %39, %struct.nvhost_ctrl* %40)
store %struct.nvhost_gr3d* %41, %struct.nvhost_gr3d** %10
%42 = load %struct.nvhost_gr3d*, %struct.nvhost_gr3d** %10
%43 = icmp ne %struct.nvhost_gr3d* %42, null
br i1 %43, label %45, label %44
44: ; preds = %38
store i32 1, i32* %3
br label %70
45: ; preds = %38
%46 = load %struct.nvhost_gr2d*, %struct.nvhost_gr2d** %9
%47 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%48 = call i32 @nvhost_gr2d_clear(%struct.nvhost_gr2d* %46, %struct.nvmap_framebuffer* %47, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 1, i32* %3
br label %70
52: ; preds = %45
%53 = load %struct.nvhost_gr3d*, %struct.nvhost_gr3d** %10
%54 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%55 = call i32 @nvhost_gr3d_triangle(%struct.nvhost_gr3d* %53, %struct.nvmap_framebuffer* %54)
store i32 %55, i32* %13
%56 = load i32, i32* %13
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %3
br label %70
59: ; preds = %52
%60 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%61 = call i32 @nvmap_framebuffer_save(%struct.nvmap_framebuffer* %60, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%62 = load %struct.nvmap_framebuffer*, %struct.nvmap_framebuffer** %6
%63 = call i32 @nvmap_framebuffer_free(%struct.nvmap_framebuffer* %62)
%64 = load %struct.nvhost_gr3d*, %struct.nvhost_gr3d** %10
%65 = call i32 @nvhost_gr3d_close(%struct.nvhost_gr3d* %64)
%66 = load %struct.nvhost_ctrl*, %struct.nvhost_ctrl** %11
%67 = call i32 @nvhost_ctrl_close(%struct.nvhost_ctrl* %66)
%68 = load %struct.nvmap*, %struct.nvmap** %12
%69 = call i32 @nvmap_close(%struct.nvmap* %68)
store i32 0, i32* %3
br label %70
70: ; preds = %59, %58, %51, %44, %37, %30, %22, %17
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.nvmap = type { i32 }
%struct.nvhost_ctrl = type { i32 }
%struct.nvmap_framebuffer = type { i32 }
%struct.nvhost_gr2d = type { i32 }
%struct.nvhost_gr3d = 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 %29, 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 %29, 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 %29, 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 %29, label %14
14: ; preds = %11
%15 = tail call %struct.nvhost_gr3d* @nvhost_gr3d_open(%struct.nvmap* %3, %struct.nvhost_ctrl* %6)
%16 = icmp eq %struct.nvhost_gr3d* %15, null
br i1 %16, label %29, label %17
17: ; preds = %14
%18 = tail call i32 @nvhost_gr2d_clear(%struct.nvhost_gr2d* %12, %struct.nvmap_framebuffer* %9, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 1.000000e+00)
%19 = icmp slt i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = tail call i32 @nvhost_gr3d_triangle(%struct.nvhost_gr3d* %15, %struct.nvmap_framebuffer* %9)
%22 = icmp slt i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = tail call i32 @nvmap_framebuffer_save(%struct.nvmap_framebuffer* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @nvmap_framebuffer_free(%struct.nvmap_framebuffer* %9)
%26 = tail call i32 @nvhost_gr3d_close(%struct.nvhost_gr3d* %15)
%27 = tail call i32 @nvhost_ctrl_close(%struct.nvhost_ctrl* %6)
%28 = tail call i32 @nvmap_close(%struct.nvmap* %3)
br label %29
29: ; preds = %20, %17, %14, %11, %8, %5, %2, %23
%30 = phi i32 [ 0, %23 ], [ 1, %2 ], [ 1, %5 ], [ 1, %8 ], [ 1, %11 ], [ 1, %14 ], [ 1, %17 ], [ 1, %20 ]
ret i32 %30
}