#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 GLsizei;
typedef int GLint;
typedef int /*<<< orphan*/ GLenum;

/* Variables and functions */
int GLU_INVALID_ENUM;
int GLU_INVALID_VALUE;
int /*<<< orphan*/ GL_BITMAP;
int checkMipmapArgs(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ closestFit3D(int /*<<< orphan*/, int, int, int, int,
                                int /*<<< orphan*/, int /*<<< orphan*/, int *,
                                int *, int *);
int computeLog(int);
int gluBuild3DMipmapLevelsCore(int /*<<< orphan*/, int, int, int, int, int, int,
                               int, int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/, int,
                               void const *);
GLint gluBuild3DMipmaps(GLenum target, GLint internalFormat, GLsizei width,
                        GLsizei height, GLsizei depth, GLenum format,
                        GLenum type, const void *data) {
  GLint widthPowerOf2, heightPowerOf2, depthPowerOf2;
  int level, levels;
  int rc = checkMipmapArgs(internalFormat, format, type);
  if (rc != 0)
    return rc;
  if (width < 1 || height < 1 || depth < 1) {
    return GLU_INVALID_VALUE;
  }
  if (type == GL_BITMAP) {
    return GLU_INVALID_ENUM;
  }
  closestFit3D(target, width, height, depth, internalFormat, format, type,
               &widthPowerOf2, &heightPowerOf2, &depthPowerOf2);
  levels = computeLog(widthPowerOf2);
  level = computeLog(heightPowerOf2);
  if (level > levels)
    levels = level;
  level = computeLog(depthPowerOf2);
  if (level > levels)
    levels = level;
  return gluBuild3DMipmapLevelsCore(
      target, internalFormat, width, height, depth, widthPowerOf2,
      heightPowerOf2, depthPowerOf2, format, type, 0, 0, levels, data);
}


x86 assembly (clang, -O0):
<gluBuild3DMipmaps>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %edx,-0x30(%rbp)
mov    %ecx,-0x34(%rbp)
mov    %r8d,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    0x10(%rbp),%edx
call   1030 <checkMipmapArgs@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1193 <gluBuild3DMipmaps+0x53>
mov    -0x54(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12c6 <gluBuild3DMipmaps+0x186>
cmpl   $0x1,-0x30(%rbp)
jl     11b1 <gluBuild3DMipmaps+0x71>
cmpl   $0x1,-0x34(%rbp)
jl     11b1 <gluBuild3DMipmaps+0x71>
cmpl   $0x1,-0x38(%rbp)
jge    11c2 <gluBuild3DMipmaps+0x82>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12c6 <gluBuild3DMipmaps+0x186>
mov    0x10(%rbp),%eax
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%eax
jne    11e5 <gluBuild3DMipmaps+0xa5>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    12c6 <gluBuild3DMipmaps+0x186>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    0x10(%rbp),%ebx
lea    -0x40(%rbp),%r11
lea    -0x44(%rbp),%r10
lea    -0x48(%rbp),%rax
mov    %ebx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <closestFit3D@plt>
mov    -0x40(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x50(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jle    1247 <gluBuild3DMipmaps+0x107>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jle    1264 <gluBuild3DMipmaps+0x124>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x40(%rbp),%r9d
mov    -0x44(%rbp),%r15d
mov    -0x48(%rbp),%r14d
mov    -0x3c(%rbp),%ebx
mov    0x10(%rbp),%r11d
mov    -0x50(%rbp),%r10d
mov    0x18(%rbp),%rax
xor    %r12d,%r12d
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %rax,0x38(%rsp)
call   1060 <gluBuild3DMipmapLevelsCore@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild3DMipmaps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    0x50(%rsp),%edx
mov    %esi,%edi
mov    %r9d,%esi
call   1030 <checkMipmapArgs@plt>
test   %eax,%eax
jne    1250 <gluBuild3DMipmaps+0x110>
test   %r14d,%r14d
jle    11a4 <gluBuild3DMipmaps+0x64>
test   %r12d,%r12d
jle    11a4 <gluBuild3DMipmaps+0x64>
mov    %r13d,%ecx
test   %r13d,%r13d
jle    11a4 <gluBuild3DMipmaps+0x64>
mov    0x2e52(%rip),%rax
mov    0x50(%rsp),%edx
cmp    %edx,(%rax)
jne    11b2 <gluBuild3DMipmaps+0x72>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
jmp    1250 <gluBuild3DMipmaps+0x110>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
jmp    1250 <gluBuild3DMipmaps+0x110>
lea    0x8(%rsp),%rax
lea    0xc(%rsp),%r10
lea    0x10(%rsp),%r11
mov    %r15d,%edi
mov    %r14d,%esi
mov    %r14d,%r13d
mov    %r12d,%edx
mov    %ecx,0x14(%rsp)
mov    %ebp,%r8d
mov    %ebx,%r9d
push   %rax
push   %r10
push   %r11
mov    0x68(%rsp),%eax
push   %rax
call   1050 <closestFit3D@plt>
add    $0x20,%rsp
mov    0x10(%rsp),%edi
call   1040 <computeLog@plt>
mov    %eax,%r14d
mov    0xc(%rsp),%edi
call   1040 <computeLog@plt>
cmp    %r14d,%eax
cmovg  %eax,%r14d
mov    0x8(%rsp),%edi
call   1040 <computeLog@plt>
cmp    %r14d,%eax
cmovg  %eax,%r14d
mov    0x10(%rsp),%r9d
mov    0xc(%rsp),%r10d
mov    0x8(%rsp),%eax
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    0x14(%rsp),%r8d
push   0x58(%rsp)
push   %r14
push   $0x0
push   $0x0
mov    0x70(%rsp),%ebp
push   %rbp
push   %rbx
push   %rax
push   %r10
call   1060 <gluBuild3DMipmapLevelsCore@plt>
add    $0x40,%rsp
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GLU_INVALID_VALUE = global i32 0
@GL_BITMAP = global i32 0
@GLU_INVALID_ENUM = global i32 0
define i32 @gluBuild3DMipmaps(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i8* %7, i8** %17
%24 = load i32, i32* %11
%25 = load i32, i32* %15
%26 = load i32, i32* %16
%27 = call i32 @checkMipmapArgs(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %23
%28 = load i32, i32* %23
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %8
%31 = load i32, i32* %23
store i32 %31, i32* %9
br label %89
32: ; preds = %8
%33 = load i32, i32* %12
%34 = icmp slt i32 %33, 1
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = load i32, i32* %13
%37 = icmp slt i32 %36, 1
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %38, %35, %32
%42 = load i32, i32* @GLU_INVALID_VALUE
store i32 %42, i32* %9
br label %89
43: ; preds = %38
%44 = load i32, i32* %16
%45 = load i32, i32* @GL_BITMAP
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i32, i32* @GLU_INVALID_ENUM
store i32 %48, i32* %9
br label %89
49: ; preds = %43
%50 = load i32, i32* %10
%51 = load i32, i32* %12
%52 = load i32, i32* %13
%53 = load i32, i32* %14
%54 = load i32, i32* %11
%55 = load i32, i32* %15
%56 = load i32, i32* %16
%57 = call i32 @closestFit3D(i32 %50, i32 %51, i32 %52, i32 %53, i32 %54, i32 %55, i32 %56, i32* %18, i32* %19, i32* %20)
%58 = load i32, i32* %18
%59 = call i32 @computeLog(i32 %58)
store i32 %59, i32* %22
%60 = load i32, i32* %19
%61 = call i32 @computeLog(i32 %60)
store i32 %61, i32* %21
%62 = load i32, i32* %21
%63 = load i32, i32* %22
%64 = icmp sgt i32 %62, %63
br i1 %64, label %65, label %67
65: ; preds = %49
%66 = load i32, i32* %21
store i32 %66, i32* %22
br label %67
67: ; preds = %65, %49
%68 = load i32, i32* %20
%69 = call i32 @computeLog(i32 %68)
store i32 %69, i32* %21
%70 = load i32, i32* %21
%71 = load i32, i32* %22
%72 = icmp sgt i32 %70, %71
br i1 %72, label %73, label %75
73: ; preds = %67
%74 = load i32, i32* %21
store i32 %74, i32* %22
br label %75
75: ; preds = %73, %67
%76 = load i32, i32* %10
%77 = load i32, i32* %11
%78 = load i32, i32* %12
%79 = load i32, i32* %13
%80 = load i32, i32* %14
%81 = load i32, i32* %18
%82 = load i32, i32* %19
%83 = load i32, i32* %20
%84 = load i32, i32* %15
%85 = load i32, i32* %16
%86 = load i32, i32* %22
%87 = load i8*, i8** %17
%88 = call i32 @gluBuild3DMipmapLevelsCore(i32 %76, i32 %77, i32 %78, i32 %79, i32 %80, i32 %81, i32 %82, i32 %83, i32 %84, i32 %85, i32 0, i32 0, i32 %86, i8* %87)
store i32 %88, i32* %9
br label %89
89: ; preds = %75, %47, %41, %30
%90 = load i32, i32* %9
ret i32 %90
}

LLVM IR (-O2):
@GLU_INVALID_VALUE = global i32 0
@GL_BITMAP = global i32 0
@GLU_INVALID_ENUM = global i32 0
define i32 @gluBuild3DMipmaps(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = bitcast i32* %9 to i8*
%13 = bitcast i32* %10 to i8*
%14 = bitcast i32* %11 to i8*
%15 = tail call i32 @checkMipmapArgs(i32 %1, i32 %5, i32 %6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %46
17: ; preds = %8
%18 = icmp slt i32 %2, 1
%19 = icmp slt i32 %3, 1
%20 = or i1 %18, %19
%21 = icmp slt i32 %4, 1
%22 = or i1 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i32, i32* @GLU_INVALID_VALUE
br label %46
25: ; preds = %17
%26 = load i32, i32* @GL_BITMAP
%27 = icmp eq i32 %26, %6
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* @GLU_INVALID_ENUM
br label %46
30: ; preds = %25
%31 = call i32 @closestFit3D(i32 %0, i32 %2, i32 %3, i32 %4, i32 %1, i32 %5, i32 %6, i32* %9, i32* %10, i32* %11)
%32 = load i32, i32* %9
%33 = call i32 @computeLog(i32 %32)
%34 = load i32, i32* %10
%35 = call i32 @computeLog(i32 %34)
%36 = icmp sgt i32 %35, %33
%37 = select i1 %36, i32 %35, i32 %33
%38 = load i32, i32* %11
%39 = call i32 @computeLog(i32 %38)
%40 = icmp sgt i32 %39, %37
%41 = select i1 %40, i32 %39, i32 %37
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = call i32 @gluBuild3DMipmapLevelsCore(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %42, i32 %43, i32 %44, i32 %5, i32 %6, i32 0, i32 0, i32 %41, i8* %7)
br label %46
46: ; preds = %8, %30, %28, %23
%47 = phi i32 [ %24, %23 ], [ %29, %28 ], [ %45, %30 ], [ %15, %8 ]
ret i32 %47
}