#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 omapfb_plane_info {
  int enabled;
  int size;
  int pos_x;
  int pos_y;
  int out_width;
  int out_height;
  int /*<<< orphan*/ member_0;
};
struct omapfb_mem_info {
  int enabled;
  int size;
  int pos_x;
  int pos_y;
  int out_width;
  int out_height;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ OMAPFB_QUERY_MEM;
int /*<<< orphan*/ OMAPFB_QUERY_PLANE;
int /*<<< orphan*/ OMAPFB_SETUP_MEM;
int /*<<< orphan*/ OMAPFB_SETUP_PLANE;
int ioctl(int, int /*<<< orphan*/, struct omapfb_plane_info *);
int /*<<< orphan*/ perror(char *);
int omap_setup_layer_(int fd, int enabled, int x, int y, int w, int h) {
  struct omapfb_plane_info pi = {
      0,
  };
  struct omapfb_mem_info mi = {
      0,
  };
  int ret;
  ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);
  if (ret != 0) {
    perror("QUERY_PLANE");
    return -1;
  }
  ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);
  if (ret != 0) {
    perror("QUERY_MEM");
    return -1;
  }
  if (pi.enabled) {
    pi.enabled = 0;
    ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
    if (ret != 0)
      perror("SETUP_PLANE");
  }
  if (mi.size < 640 * 512 * 3 * 3) {
    mi.size = 640 * 512 * 3 * 3;
    ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);
    if (ret != 0) {
      perror("SETUP_MEM");
      return -1;
    }
  }
  pi.pos_x = x;
  pi.pos_y = y;
  pi.out_width = w;
  pi.out_height = h;
  pi.enabled = enabled;
  ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);
  if (ret != 0) {
    perror("SETUP_PLANE");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<omap_setup_layer_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1030 <memset@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x1c,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     11a6 <omap_setup_layer_+0x76>
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <omap_setup_layer_+0x1a6>
mov    -0x8(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     11e0 <omap_setup_layer_+0xb0>
lea    0xe3d(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <omap_setup_layer_+0x1a6>
cmpl   $0x0,-0x38(%rbp)
je     1224 <omap_setup_layer_+0xf4>
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     121f <omap_setup_layer_+0xef>
lea    0xdfc(%rip),%rdi
call   1050 <perror@plt>
jmp    1224 <omap_setup_layer_+0xf4>
cmpl   $0x2d0000,-0x54(%rbp)
jge    1277 <omap_setup_layer_+0x147>
movl   $0x2d0000,-0x54(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1272 <omap_setup_layer_+0x142>
lea    0xdc1(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <omap_setup_layer_+0x1a6>
jmp    1277 <omap_setup_layer_+0x147>
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     12cf <omap_setup_layer_+0x19f>
lea    0xd58(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <omap_setup_layer_+0x1a6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<omap_setup_layer_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%ebp
mov    %esi,%r12d
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movups %xmm0,0xc(%rsp)
movaps %xmm0,(%rsp)
movups %xmm0,0x2c(%rsp)
movaps %xmm0,0x20(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
jne    121e <omap_setup_layer_+0xfe>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    1227 <omap_setup_layer_+0x107>
cmpl   $0x0,(%rsp)
je     11b2 <omap_setup_layer_+0x92>
movl   $0x0,(%rsp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    1239 <omap_setup_layer_+0x119>
cmpl   $0x2cffff,0x24(%rsp)
jg     11dd <omap_setup_layer_+0xbd>
movl   $0x2d0000,0x24(%rsp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    1255 <omap_setup_layer_+0x135>
mov    %ebp,0x8(%rsp)
mov    %r13d,0xc(%rsp)
mov    %r15d,0x10(%rsp)
mov    %r14d,0x14(%rsp)
mov    %r12d,(%rsp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1230 <omap_setup_layer_+0x110>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddb(%rip),%rdi
jmp    125c <omap_setup_layer_+0x13c>
lea    0xdde(%rip),%rdi
jmp    125c <omap_setup_layer_+0x13c>
lea    0xddf(%rip),%rdi
jmp    125c <omap_setup_layer_+0x13c>
lea    0xdd6(%rip),%rdi
call   1040 <perror@plt>
cmpl   $0x2cffff,0x24(%rsp)
jle    11bc <omap_setup_layer_+0x9c>
jmp    11dd <omap_setup_layer_+0xbd>
lea    0xdc6(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    120f <omap_setup_layer_+0xef>

LLVM IR (-O0):
%struct.omapfb_plane_info = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.omapfb_mem_info = type { i32, i32, i32, i32, i32, i32, i32 }
@OMAPFB_QUERY_PLANE = global i32 0
@.str = [12 x i8] c"QUERY_PLANE\00"
@OMAPFB_QUERY_MEM = global i32 0
@.str.1 = [10 x i8] c"QUERY_MEM\00"
@OMAPFB_SETUP_PLANE = global i32 0
@.str.2 = [12 x i8] c"SETUP_PLANE\00"
@OMAPFB_SETUP_MEM = global i32 0
@.str.3 = [10 x i8] c"SETUP_MEM\00"
define i32 @omap_setup_layer_(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.omapfb_plane_info
%15 = alloca %struct.omapfb_mem_info
%16 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%17 = bitcast %struct.omapfb_plane_info* %14 to i8*
%18 = bitcast %struct.omapfb_mem_info* %15 to i8*
%19 = load i32, i32* %8
%20 = load i32, i32* @OMAPFB_QUERY_PLANE
%21 = call i32 @ioctl(i32 %19, i32 %20, %struct.omapfb_plane_info* %14)
store i32 %21, i32* %16
%22 = load i32, i32* %16
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %7
br label %83
26: ; preds = %6
%27 = load i32, i32* %8
%28 = load i32, i32* @OMAPFB_QUERY_MEM
%29 = bitcast %struct.omapfb_mem_info* %15 to %struct.omapfb_plane_info*
%30 = call i32 @ioctl(i32 %27, i32 %28, %struct.omapfb_plane_info* %29)
store i32 %30, i32* %16
%31 = load i32, i32* %16
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %83
35: ; preds = %26
%36 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 0
%37 = load i32, i32* %36
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 0
store i32 0, i32* %40
%41 = load i32, i32* %8
%42 = load i32, i32* @OMAPFB_SETUP_PLANE
%43 = call i32 @ioctl(i32 %41, i32 %42, %struct.omapfb_plane_info* %14)
store i32 %43, i32* %16
%44 = load i32, i32* %16
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %39
br label %49
49: ; preds = %48, %35
%50 = getelementptr inbounds %struct.omapfb_mem_info, %struct.omapfb_mem_info* %15, i32 0, i32 1
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, 2949120
br i1 %52, label %53, label %64
53: ; preds = %49
%54 = getelementptr inbounds %struct.omapfb_mem_info, %struct.omapfb_mem_info* %15, i32 0, i32 1
store i32 2949120, i32* %54
%55 = load i32, i32* %8
%56 = load i32, i32* @OMAPFB_SETUP_MEM
%57 = bitcast %struct.omapfb_mem_info* %15 to %struct.omapfb_plane_info*
%58 = call i32 @ioctl(i32 %55, i32 %56, %struct.omapfb_plane_info* %57)
store i32 %58, i32* %16
%59 = load i32, i32* %16
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %53
%62 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %7
br label %83
63: ; preds = %53
br label %64
64: ; preds = %63, %49
%65 = load i32, i32* %10
%66 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 2
store i32 %65, i32* %66
%67 = load i32, i32* %11
%68 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 3
store i32 %67, i32* %68
%69 = load i32, i32* %12
%70 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 4
store i32 %69, i32* %70
%71 = load i32, i32* %13
%72 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 5
store i32 %71, i32* %72
%73 = load i32, i32* %9
%74 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %14, i32 0, i32 0
store i32 %73, i32* %74
%75 = load i32, i32* %8
%76 = load i32, i32* @OMAPFB_SETUP_PLANE
%77 = call i32 @ioctl(i32 %75, i32 %76, %struct.omapfb_plane_info* %14)
store i32 %77, i32* %16
%78 = load i32, i32* %16
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %64
%81 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %83
82: ; preds = %64
store i32 0, i32* %7
br label %83
83: ; preds = %82, %80, %61, %33, %24
%84 = load i32, i32* %7
ret i32 %84
}

LLVM IR (-O2):
%struct.omapfb_plane_info = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.omapfb_mem_info = type { i32, i32, i32, i32, i32, i32, i32 }
@OMAPFB_QUERY_PLANE = global i32 0
@.str = [12 x i8] c"QUERY_PLANE\00"
@OMAPFB_QUERY_MEM = global i32 0
@.str.1 = [10 x i8] c"QUERY_MEM\00"
@OMAPFB_SETUP_PLANE = global i32 0
@.str.2 = [12 x i8] c"SETUP_PLANE\00"
@OMAPFB_SETUP_MEM = global i32 0
@.str.3 = [10 x i8] c"SETUP_MEM\00"
define i32 @omap_setup_layer_(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca %struct.omapfb_plane_info
%8 = alloca %struct.omapfb_mem_info
%9 = bitcast %struct.omapfb_plane_info* %7 to i8*
%10 = bitcast %struct.omapfb_mem_info* %8 to i8*
%11 = load i32, i32* @OMAPFB_QUERY_PLANE
%12 = call i32 @ioctl(i32 %0, i32 %11, %struct.omapfb_plane_info* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %6
%15 = load i32, i32* @OMAPFB_QUERY_MEM
%16 = bitcast %struct.omapfb_mem_info* %8 to %struct.omapfb_plane_info*
%17 = call i32 @ioctl(i32 %0, i32 %15, %struct.omapfb_plane_info* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %45
19: ; preds = %14
%20 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %7, i64 0, i32 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
store i32 0, i32* %20
%24 = load i32, i32* @OMAPFB_SETUP_PLANE
%25 = call i32 @ioctl(i32 %0, i32 %24, %struct.omapfb_plane_info* %7)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %23, %27, %19
%30 = getelementptr inbounds %struct.omapfb_mem_info, %struct.omapfb_mem_info* %8, i64 0, i32 1
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 2949120
br i1 %32, label %33, label %37
33: ; preds = %29
store i32 2949120, i32* %30
%34 = load i32, i32* @OMAPFB_SETUP_MEM
%35 = call i32 @ioctl(i32 %0, i32 %34, %struct.omapfb_plane_info* %16)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %33, %29
%38 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %7, i64 0, i32 2
store i32 %2, i32* %38
%39 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %7, i64 0, i32 3
store i32 %3, i32* %39
%40 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %7, i64 0, i32 4
store i32 %4, i32* %40
%41 = getelementptr inbounds %struct.omapfb_plane_info, %struct.omapfb_plane_info* %7, i64 0, i32 5
store i32 %5, i32* %41
store i32 %1, i32* %20
%42 = load i32, i32* @OMAPFB_SETUP_PLANE
%43 = call i32 @ioctl(i32 %0, i32 %42, %struct.omapfb_plane_info* %7)
%44 = icmp eq i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %37, %33, %14, %6
%46 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %14 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %33 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %37 ]
%47 = call i32 @perror(i8* %46)
br label %48
48: ; preds = %45, %37
%49 = phi i32 [ 0, %37 ], [ -1, %45 ]
ret i32 %49
}