#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 scalar_t__ GLenum;

/* Variables and functions */
int GLU_INVALID_ENUM;
int GLU_INVALID_VALUE;
scalar_t__ GL_BITMAP;
int checkMipmapArgs(int, scalar_t__, scalar_t__);
int computeLog(int);
int gluBuild3DMipmapLevelsCore(scalar_t__, int, int, int, int, int, int, int,
                               scalar_t__, scalar_t__, int, int, int,
                               void const *);
int /*<<< orphan*/ isLegalLevels(int, int, int, int);
GLint gluBuild3DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width,
                             GLsizei height, GLsizei depth, GLenum format,
                             GLenum type, GLint userLevel, GLint baseLevel,
                             GLint maxLevel, const void *data) {
  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;
  }
  levels = computeLog(width);
  level = computeLog(height);
  if (level > levels)
    levels = level;
  level = computeLog(depth);
  if (level > levels)
    levels = level;
  levels += userLevel;
  if (!isLegalLevels(userLevel, baseLevel, maxLevel, levels))
    return GLU_INVALID_VALUE;
  return gluBuild3DMipmapLevelsCore(target, internalFormat, width, height,
                                    depth, width, height, depth, format, type,
                                    userLevel, baseLevel, maxLevel, data);
}


x86 assembly (clang, -O0):
<gluBuild3DMipmapLevels>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x38(%rbp)
mov    %esi,-0x3c(%rbp)
mov    %edx,-0x40(%rbp)
mov    %ecx,-0x44(%rbp)
mov    %r8d,-0x48(%rbp)
mov    %r9,-0x50(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    0x10(%rbp),%rdx
call   1040 <checkMipmapArgs@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     119f <gluBuild3DMipmapLevels+0x5f>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ce <gluBuild3DMipmapLevels+0x18e>
cmpl   $0x1,-0x40(%rbp)
jl     11bd <gluBuild3DMipmapLevels+0x7d>
cmpl   $0x1,-0x44(%rbp)
jl     11bd <gluBuild3DMipmapLevels+0x7d>
cmpl   $0x1,-0x48(%rbp)
jge    11ce <gluBuild3DMipmapLevels+0x8e>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ce <gluBuild3DMipmapLevels+0x18e>
mov    0x10(%rbp),%rax
mov    0x2e07(%rip),%rcx
cmp    (%rcx),%rax
jne    11f3 <gluBuild3DMipmapLevels+0xb3>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ce <gluBuild3DMipmapLevels+0x18e>
mov    -0x40(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x58(%rbp)
mov    -0x44(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jle    121b <gluBuild3DMipmapLevels+0xdb>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x48(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jle    1238 <gluBuild3DMipmapLevels+0xf8>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x18(%rbp),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    0x18(%rbp),%edi
mov    0x20(%rbp),%esi
mov    0x28(%rbp),%edx
mov    -0x58(%rbp),%ecx
call   1030 <isLegalLevels@plt>
cmp    $0x0,%eax
jne    126c <gluBuild3DMipmapLevels+0x12c>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ce <gluBuild3DMipmapLevels+0x18e>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%edx
mov    -0x44(%rbp),%ecx
mov    -0x48(%rbp),%r8d
mov    -0x40(%rbp),%r9d
mov    -0x44(%rbp),%r13d
mov    -0x48(%rbp),%r12d
mov    -0x50(%rbp),%r15
mov    0x10(%rbp),%r14
mov    0x18(%rbp),%ebx
mov    0x20(%rbp),%r11d
mov    0x28(%rbp),%r10d
mov    0x30(%rbp),%rax
mov    %r13d,(%rsp)
mov    %r12d,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %ebx,0x20(%rsp)
mov    %r11d,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %rax,0x38(%rsp)
call   1060 <gluBuild3DMipmapLevelsCore@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild3DMipmapLevels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r12
mov    %r8,0x20(%rsp)
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
mov    0x60(%rsp),%rbp
mov    %esi,%edi
mov    %r9,%rsi
mov    %rbp,%rdx
call   1040 <checkMipmapArgs@plt>
test   %eax,%eax
jne    1262 <gluBuild3DMipmapLevels+0x122>
mov    %ebx,0xc(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
test   %r14d,%r14d
mov    %r13,%r15
mov    0x20(%rsp),%r13
jle    1259 <gluBuild3DMipmapLevels+0x119>
test   %r15d,%r15d
jle    1259 <gluBuild3DMipmapLevels+0x119>
test   %r13d,%r13d
jle    1259 <gluBuild3DMipmapLevels+0x119>
mov    0x2e2d(%rip),%rax
cmp    %rbp,(%rax)
jne    11c4 <gluBuild3DMipmapLevels+0x84>
mov    0x2e11(%rip),%rax
jmp    1260 <gluBuild3DMipmapLevels+0x120>
mov    0x70(%rsp),%ebp
mov    0x68(%rsp),%eax
mov    %r14d,%ebx
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <computeLog@plt>
mov    %eax,%r12d
mov    %r15d,%edi
call   1050 <computeLog@plt>
cmp    %r12d,%eax
cmovg  %eax,%r12d
mov    %r13d,%edi
call   1050 <computeLog@plt>
cmp    %r12d,%eax
cmovg  %eax,%r12d
add    %r14d,%r12d
mov    %r14d,%edi
mov    %ebp,%esi
mov    0x78(%rsp),%edx
mov    %r12d,%ecx
call   1030 <isLegalLevels@plt>
test   %eax,%eax
je     1259 <gluBuild3DMipmapLevels+0x119>
mov    0x18(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r13d,%r8d
mov    %ebx,%r9d
push   0x80(%rsp)
mov    0x80(%rsp),%eax
push   %rax
mov    0x80(%rsp),%eax
push   %rax
push   %r14
push   0x80(%rsp)
push   0x38(%rsp)
push   %r13
push   %r15
call   1060 <gluBuild3DMipmapLevelsCore@plt>
add    $0x68,%rsp
jmp    1266 <gluBuild3DMipmapLevels+0x126>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
add    $0x28,%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 i64 0
@GLU_INVALID_ENUM = global i32 0
define i32 @gluBuild3DMipmapLevels(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4, i64 %5, i64 %6, i32 %7, i32 %8, i32 %9, i8* %10) {
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
store i64 %0, i64* %13
store i32 %1, i32* %14
store i32 %2, i32* %15
store i32 %3, i32* %16
store i32 %4, i32* %17
store i64 %5, i64* %18
store i64 %6, i64* %19
store i32 %7, i32* %20
store i32 %8, i32* %21
store i32 %9, i32* %22
store i8* %10, i8** %23
%27 = load i32, i32* %14
%28 = load i64, i64* %18
%29 = load i64, i64* %19
%30 = call i32 @checkMipmapArgs(i32 %27, i64 %28, i64 %29)
store i32 %30, i32* %26
%31 = load i32, i32* %26
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %11
%34 = load i32, i32* %26
store i32 %34, i32* %12
br label %98
35: ; preds = %11
%36 = load i32, i32* %15
%37 = icmp slt i32 %36, 1
br i1 %37, label %44, label %38
38: ; preds = %35
%39 = load i32, i32* %16
%40 = icmp slt i32 %39, 1
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %17
%43 = icmp slt i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %41, %38, %35
%45 = load i32, i32* @GLU_INVALID_VALUE
store i32 %45, i32* %12
br label %98
46: ; preds = %41
%47 = load i64, i64* %19
%48 = load i64, i64* @GL_BITMAP
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i32, i32* @GLU_INVALID_ENUM
store i32 %51, i32* %12
br label %98
52: ; preds = %46
%53 = load i32, i32* %15
%54 = call i32 @computeLog(i32 %53)
store i32 %54, i32* %25
%55 = load i32, i32* %16
%56 = call i32 @computeLog(i32 %55)
store i32 %56, i32* %24
%57 = load i32, i32* %24
%58 = load i32, i32* %25
%59 = icmp sgt i32 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = load i32, i32* %24
store i32 %61, i32* %25
br label %62
62: ; preds = %60, %52
%63 = load i32, i32* %17
%64 = call i32 @computeLog(i32 %63)
store i32 %64, i32* %24
%65 = load i32, i32* %24
%66 = load i32, i32* %25
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = load i32, i32* %24
store i32 %69, i32* %25
br label %70
70: ; preds = %68, %62
%71 = load i32, i32* %20
%72 = load i32, i32* %25
%73 = add nsw i32 %72, %71
store i32 %73, i32* %25
%74 = load i32, i32* %20
%75 = load i32, i32* %21
%76 = load i32, i32* %22
%77 = load i32, i32* %25
%78 = call i32 @isLegalLevels(i32 %74, i32 %75, i32 %76, i32 %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %70
%81 = load i32, i32* @GLU_INVALID_VALUE
store i32 %81, i32* %12
br label %98
82: ; preds = %70
%83 = load i64, i64* %13
%84 = load i32, i32* %14
%85 = load i32, i32* %15
%86 = load i32, i32* %16
%87 = load i32, i32* %17
%88 = load i32, i32* %15
%89 = load i32, i32* %16
%90 = load i32, i32* %17
%91 = load i64, i64* %18
%92 = load i64, i64* %19
%93 = load i32, i32* %20
%94 = load i32, i32* %21
%95 = load i32, i32* %22
%96 = load i8*, i8** %23
%97 = call i32 @gluBuild3DMipmapLevelsCore(i64 %83, i32 %84, i32 %85, i32 %86, i32 %87, i32 %88, i32 %89, i32 %90, i64 %91, i64 %92, i32 %93, i32 %94, i32 %95, i8* %96)
store i32 %97, i32* %12
br label %98
98: ; preds = %82, %80, %50, %44, %33
%99 = load i32, i32* %12
ret i32 %99
}

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