#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 GLint;
typedef int GLenum;

/* Variables and functions */
#define GL_ABGR_EXT 162
#define GL_ALPHA 161
#define GL_BGR 160
#define GL_BGRA 159
#define GL_BITMAP 158
#define GL_BLUE 157
#define GL_BYTE 156
#define GL_COLOR_INDEX 155
#define GL_DEPTH_COMPONENT 154
#define GL_FLOAT 153
#define GL_GREEN 152
#define GL_INT 151
#define GL_INTENSITY 150
#define GL_LUMINANCE 149
#define GL_LUMINANCE_ALPHA 148
#define GL_RED 147
#define GL_RGB 146
#define GL_RGBA 145
#define GL_SHORT 144
#define GL_STENCIL_INDEX 143
#define GL_UNSIGNED_BYTE 142
#define GL_UNSIGNED_BYTE_2_3_3_REV 141
#define GL_UNSIGNED_BYTE_3_3_2 140
#define GL_UNSIGNED_INT 139
#define GL_UNSIGNED_INT_10_10_10_2 138
#define GL_UNSIGNED_INT_2_10_10_10_REV 137
#define GL_UNSIGNED_INT_8_8_8_8 136
#define GL_UNSIGNED_INT_8_8_8_8_REV 135
#define GL_UNSIGNED_SHORT 134
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 133
#define GL_UNSIGNED_SHORT_4_4_4_4 132
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 131
#define GL_UNSIGNED_SHORT_5_5_5_1 130
#define GL_UNSIGNED_SHORT_5_6_5 129
#define GL_UNSIGNED_SHORT_5_6_5_REV 128
GLint __glReadPixels_size(GLenum format, GLenum type, GLint w, GLint h) {
  GLint elements, esize;
  GLint rowsize, padding;
  if (w < 0 || h < 0) {
    return -1;
  }
  switch (format) {
  case GL_COLOR_INDEX:
  case GL_STENCIL_INDEX:
  case GL_DEPTH_COMPONENT:
    elements = 1;
    break;
  case GL_RED:
  case GL_GREEN:
  case GL_BLUE:
  case GL_ALPHA:
  case GL_LUMINANCE:
  case GL_INTENSITY:
    elements = 1;
    break;
  case GL_LUMINANCE_ALPHA:
    elements = 2;
    break;
  case GL_RGB:
  case GL_BGR:
    elements = 3;
    break;
  case GL_RGBA:
  case GL_BGRA:
  case GL_ABGR_EXT:
    elements = 4;
    break;
  default:
    return -1;
  }
  switch (type) {
  case GL_BITMAP:
    if (format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX) {
      rowsize = ((w * elements) + 7) / 8;
      padding = rowsize % 4;
      if (padding) {
        rowsize += 4 - padding;
      }
      return (rowsize * h);
    } else {
      return -1;
    }
  case GL_BYTE:
  case GL_UNSIGNED_BYTE:
    esize = 1;
    break;
  case GL_UNSIGNED_BYTE_3_3_2:
  case GL_UNSIGNED_BYTE_2_3_3_REV:
    esize = 1;
    elements = 1;
    break;
  case GL_SHORT:
  case GL_UNSIGNED_SHORT:
    esize = 2;
    break;
  case GL_UNSIGNED_SHORT_5_6_5:
  case GL_UNSIGNED_SHORT_5_6_5_REV:
  case GL_UNSIGNED_SHORT_4_4_4_4:
  case GL_UNSIGNED_SHORT_4_4_4_4_REV:
  case GL_UNSIGNED_SHORT_5_5_5_1:
  case GL_UNSIGNED_SHORT_1_5_5_5_REV:
    esize = 2;
    elements = 1;
    break;
  case GL_INT:
  case GL_UNSIGNED_INT:
  case GL_FLOAT:
    esize = 4;
    break;
  case GL_UNSIGNED_INT_8_8_8_8:
  case GL_UNSIGNED_INT_8_8_8_8_REV:
  case GL_UNSIGNED_INT_10_10_10_2:
  case GL_UNSIGNED_INT_2_10_10_10_REV:
    esize = 4;
    elements = 1;
    break;
  default:
    return -1;
  }
  rowsize = w * elements * esize;
  padding = rowsize % 4;
  if (padding) {
    rowsize += 4 - padding;
  }
  return (rowsize * h);
}


x86 assembly (clang, -O0):
<__glReadPixels_size>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1124 <__glReadPixels_size+0x24>
cmpl   $0x0,-0x14(%rbp)
jge    1130 <__glReadPixels_size+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e3 <__glReadPixels_size+0x1e3>
mov    -0x8(%rbp),%eax
add    $0xffffff71,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x13,%eax
ja     1197 <__glReadPixels_size+0x97>
mov    -0x30(%rbp),%rax
lea    0xeae(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    11a3 <__glReadPixels_size+0xa3>
movl   $0x1,-0x18(%rbp)
jmp    11a3 <__glReadPixels_size+0xa3>
movl   $0x2,-0x18(%rbp)
jmp    11a3 <__glReadPixels_size+0xa3>
movl   $0x3,-0x18(%rbp)
jmp    11a3 <__glReadPixels_size+0xa3>
movl   $0x4,-0x18(%rbp)
jmp    11a3 <__glReadPixels_size+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e3 <__glReadPixels_size+0x1e3>
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x1e,%eax
ja     1299 <__glReadPixels_size+0x199>
mov    -0x38(%rbp),%rax
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x9b,-0x8(%rbp)
je     11e6 <__glReadPixels_size+0xe6>
cmpl   $0x8f,-0x8(%rbp)
jne    1230 <__glReadPixels_size+0x130>
mov    -0x10(%rbp),%eax
imul   -0x18(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1221 <__glReadPixels_size+0x121>
mov    $0x4,%eax
sub    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e3 <__glReadPixels_size+0x1e3>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e3 <__glReadPixels_size+0x1e3>
movl   $0x1,-0x1c(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0x2,-0x1c(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0x2,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0x4,-0x1c(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0x4,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    12a5 <__glReadPixels_size+0x1a5>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e3 <__glReadPixels_size+0x1e3>
mov    -0x10(%rbp),%eax
imul   -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12d9 <__glReadPixels_size+0x1d9>
mov    $0x4,%eax
sub    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__glReadPixels_size>:
mov    $0xffffffff,%eax
mov    %ecx,%r8d
or     %edx,%r8d
js     11c1 <__glReadPixels_size+0xc1>
lea    -0x8f(%rdi),%r8d
cmp    $0x13,%r8d
ja     11c1 <__glReadPixels_size+0xc1>
mov    $0xf5afd,%r9d
bt     %r8d,%r9d
jae    11c1 <__glReadPixels_size+0xc1>
add    $0xffffff80,%esi
cmp    $0x1e,%esi
ja     11c1 <__glReadPixels_size+0xc1>
movslq %r8d,%r8
lea    0xf34(%rip),%r9
mov    (%r9,%r8,4),%r8d
mov    $0x1,%r9d
lea    0xea7(%rip),%r10
movslq (%r10,%rsi,4),%rsi
add    %r10,%rsi
jmp    *%rsi
mov    $0x2,%r9d
jmp    1170 <__glReadPixels_size+0x70>
mov    $0x4,%r9d
mov    $0x1,%r8d
jmp    1194 <__glReadPixels_size+0x94>
mov    $0x4,%r9d
jmp    1194 <__glReadPixels_size+0x94>
mov    $0x2,%r9d
jmp    1194 <__glReadPixels_size+0x94>
mov    $0x1,%r8d
mov    $0x1,%r9d
imul   %edx,%r8d
imul   %r9d,%r8d
lea    0x3(%r8),%eax
test   %r8d,%r8d
cmovns %r8d,%eax
and    $0xfffffffc,%eax
mov    %r8d,%edx
sub    %eax,%edx
mov    $0x4,%eax
sub    %edx,%eax
test   %edx,%edx
cmove  %edx,%eax
add    %r8d,%eax
imul   %ecx,%eax
ret
cmp    $0x9b,%edi
je     11d2 <__glReadPixels_size+0xd2>
cmp    $0x8f,%edi
jne    11c1 <__glReadPixels_size+0xc1>
imul   %edx,%r8d
lea    0x7(%r8),%eax
add    $0xe,%r8d
test   %eax,%eax
cmovns %eax,%r8d
sar    $0x3,%r8d
jmp    119c <__glReadPixels_size+0x9c>

LLVM IR (-O0):
define i32 @__glReadPixels_size(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %4
store i32 -1, i32* %5
br label %82
20: ; preds = %16
%21 = load i32, i32* %6
switch i32 %21, label %27 [
i32 155, label %22
i32 143, label %22
i32 154, label %22
i32 147, label %23
i32 152, label %23
i32 157, label %23
i32 161, label %23
i32 149, label %23
i32 150, label %23
i32 148, label %24
i32 146, label %25
i32 160, label %25
i32 145, label %26
i32 159, label %26
i32 162, label %26
]
22: ; preds = %20, %20, %20
store i32 1, i32* %10
br label %28
23: ; preds = %20, %20, %20, %20, %20, %20
store i32 1, i32* %10
br label %28
24: ; preds = %20
store i32 2, i32* %10
br label %28
25: ; preds = %20, %20
store i32 3, i32* %10
br label %28
26: ; preds = %20, %20, %20
store i32 4, i32* %10
br label %28
27: ; preds = %20
store i32 -1, i32* %5
br label %82
28: ; preds = %26, %25, %24, %23, %22
%29 = load i32, i32* %7
switch i32 %29, label %62 [
i32 158, label %30
i32 156, label %56
i32 142, label %56
i32 140, label %57
i32 141, label %57
i32 144, label %58
i32 134, label %58
i32 129, label %59
i32 128, label %59
i32 132, label %59
i32 131, label %59
i32 130, label %59
i32 133, label %59
i32 151, label %60
i32 139, label %60
i32 153, label %60
i32 136, label %61
i32 135, label %61
i32 138, label %61
i32 137, label %61
]
30: ; preds = %28
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 155
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 143
br i1 %35, label %36, label %55
36: ; preds = %33, %30
%37 = load i32, i32* %8
%38 = load i32, i32* %10
%39 = mul nsw i32 %37, %38
%40 = add nsw i32 %39, 7
%41 = sdiv i32 %40, 8
store i32 %41, i32* %12
%42 = load i32, i32* %12
%43 = srem i32 %42, 4
store i32 %43, i32* %13
%44 = load i32, i32* %13
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %36
%47 = load i32, i32* %13
%48 = sub nsw i32 4, %47
%49 = load i32, i32* %12
%50 = add nsw i32 %49, %48
store i32 %50, i32* %12
br label %51
51: ; preds = %46, %36
%52 = load i32, i32* %12
%53 = load i32, i32* %9
%54 = mul nsw i32 %52, %53
store i32 %54, i32* %5
br label %82
55: ; preds = %33
store i32 -1, i32* %5
br label %82
56: ; preds = %28, %28
store i32 1, i32* %11
br label %63
57: ; preds = %28, %28
store i32 1, i32* %11
store i32 1, i32* %10
br label %63
58: ; preds = %28, %28
store i32 2, i32* %11
br label %63
59: ; preds = %28, %28, %28, %28, %28, %28
store i32 2, i32* %11
store i32 1, i32* %10
br label %63
60: ; preds = %28, %28, %28
store i32 4, i32* %11
br label %63
61: ; preds = %28, %28, %28, %28
store i32 4, i32* %11
store i32 1, i32* %10
br label %63
62: ; preds = %28
store i32 -1, i32* %5
br label %82
63: ; preds = %61, %60, %59, %58, %57, %56
%64 = load i32, i32* %8
%65 = load i32, i32* %10
%66 = mul nsw i32 %64, %65
%67 = load i32, i32* %11
%68 = mul nsw i32 %66, %67
store i32 %68, i32* %12
%69 = load i32, i32* %12
%70 = srem i32 %69, 4
store i32 %70, i32* %13
%71 = load i32, i32* %13
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %63
%74 = load i32, i32* %13
%75 = sub nsw i32 4, %74
%76 = load i32, i32* %12
%77 = add nsw i32 %76, %75
store i32 %77, i32* %12
br label %78
78: ; preds = %73, %63
%79 = load i32, i32* %12
%80 = load i32, i32* %9
%81 = mul nsw i32 %79, %80
store i32 %81, i32* %5
br label %82
82: ; preds = %78, %62, %55, %51, %27, %19
%83 = load i32, i32* %5
ret i32 %83
}

LLVM IR (-O2):
@switch.table.__glReadPixels_size = [20 x i32] [i32 1, i32 1, i32 4, i32 3, i32 1, i32 2, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 4, i32 3, i32 1, i32 4]
define i32 @__glReadPixels_size(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = or i32 %3, %2
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %45
7: ; preds = %4
%8 = add i32 %0, -143
%9 = icmp ult i32 %8, 20
br i1 %9, label %10, label %45
10: ; preds = %7
%11 = lshr i32 1006333, %8
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %45, label %14
14: ; preds = %10
%15 = sext i32 %8 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* @switch.table.__glReadPixels_size, i64 0, i64 %15
%17 = load i32, i32* %16
switch i32 %1, label %45 [
i32 158, label %18
i32 156, label %34
i32 142, label %34
i32 140, label %29
i32 141, label %29
i32 144, label %30
i32 134, label %30
i32 129, label %31
i32 128, label %31
i32 132, label %31
i32 131, label %31
i32 130, label %31
i32 133, label %31
i32 151, label %32
i32 139, label %32
i32 153, label %32
i32 136, label %33
i32 135, label %33
i32 138, label %33
i32 137, label %33
]
18: ; preds = %14
switch i32 %0, label %45 [
i32 155, label %19
i32 143, label %19
]
19: ; preds = %18, %18
%20 = mul nsw i32 %17, %2
%21 = add nsw i32 %20, 7
%22 = sdiv i32 %21, 8
%23 = srem i32 %22, 4
%24 = icmp eq i32 %23, 0
%25 = sub nsw i32 4, %23
%26 = select i1 %24, i32 0, i32 %25
%27 = add nsw i32 %26, %22
%28 = mul nsw i32 %27, %3
br label %45
29: ; preds = %14, %14
br label %34
30: ; preds = %14, %14
br label %34
31: ; preds = %14, %14, %14, %14, %14, %14
br label %34
32: ; preds = %14, %14, %14
br label %34
33: ; preds = %14, %14, %14, %14
br label %34
34: ; preds = %14, %14, %33, %32, %31, %30, %29
%35 = phi i32 [ 1, %33 ], [ %17, %32 ], [ 1, %31 ], [ %17, %30 ], [ 1, %29 ], [ %17, %14 ], [ %17, %14 ]
%36 = phi i32 [ 4, %33 ], [ 4, %32 ], [ 2, %31 ], [ 2, %30 ], [ 1, %29 ], [ 1, %14 ], [ 1, %14 ]
%37 = mul nsw i32 %35, %2
%38 = mul nsw i32 %37, %36
%39 = srem i32 %38, 4
%40 = icmp eq i32 %39, 0
%41 = sub nsw i32 4, %39
%42 = select i1 %40, i32 0, i32 %41
%43 = add nsw i32 %42, %38
%44 = mul nsw i32 %43, %3
br label %45
45: ; preds = %10, %7, %14, %18, %4, %34, %19
%46 = phi i32 [ %44, %34 ], [ %28, %19 ], [ -1, %4 ], [ -1, %7 ], [ -1, %18 ], [ -1, %14 ], [ -1, %10 ]
ret i32 %46
}