#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_VALUE;
int checkMipmapArgs(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ closestFit(int /*<<< orphan*/, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/, int *,
                              int *);
int computeLog(int);
int gluBuild2DMipmapLevelsCore(int /*<<< orphan*/, int, int, int, int, int,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/, int,
                               void const *);
GLint gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width,
                        GLsizei height, GLenum format, GLenum type,
                        const void *data) {
  GLint widthPowerOf2, heightPowerOf2;
  int level, levels;
  int rc = checkMipmapArgs(internalFormat, format, type);
  if (rc != 0)
    return rc;
  if (width < 1 || height < 1) {
    return GLU_INVALID_VALUE;
  }
  closestFit(target, width, height, internalFormat, format, type,
             &widthPowerOf2, &heightPowerOf2);
  levels = computeLog(widthPowerOf2);
  level = computeLog(heightPowerOf2);
  if (level > levels)
    levels = level;
  return gluBuild2DMipmapLevelsCore(target, internalFormat, width, height,
                                    widthPowerOf2, heightPowerOf2, format, type,
                                    0, 0, levels, data);
}


x86 assembly (clang, -O0):
<gluBuild2DMipmaps>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <checkMipmapArgs@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     1189 <gluBuild2DMipmaps+0x49>
mov    -0x40(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1250 <gluBuild2DMipmaps+0x110>
cmpl   $0x1,-0x20(%rbp)
jl     119d <gluBuild2DMipmaps+0x5d>
cmpl   $0x1,-0x24(%rbp)
jge    11ae <gluBuild2DMipmaps+0x6e>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1250 <gluBuild2DMipmaps+0x110>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    -0x30(%rbp),%r10
lea    -0x34(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <closestFit@plt>
mov    -0x30(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    1200 <gluBuild2DMipmaps+0xc0>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x34(%rbp),%r9d
mov    -0x28(%rbp),%ebx
mov    -0x2c(%rbp),%r11d
mov    -0x3c(%rbp),%r10d
mov    0x10(%rbp),%rax
xor    %r14d,%r14d
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1050 <gluBuild2DMipmapLevelsCore@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild2DMipmaps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%ebx
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebp
mov    %edi,%r13d
mov    %esi,%edi
mov    %r8d,%esi
mov    %r9d,%edx
call   1030 <checkMipmapArgs@plt>
test   %eax,%eax
jne    11fd <gluBuild2DMipmaps+0xbd>
test   %r12d,%r12d
jle    11f4 <gluBuild2DMipmaps+0xb4>
test   %r15d,%r15d
jle    11f4 <gluBuild2DMipmaps+0xb4>
lea    0xc(%rsp),%rax
lea    0x10(%rsp),%r10
mov    %r13d,%edi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
mov    %ebx,%r9d
push   %rax
push   %r10
call   1060 <closestFit@plt>
add    $0x10,%rsp
mov    0x10(%rsp),%edi
call   1040 <computeLog@plt>
mov    %r13d,0x14(%rsp)
mov    %eax,%r13d
mov    0xc(%rsp),%edi
call   1040 <computeLog@plt>
cmp    %r13d,%eax
cmovg  %eax,%r13d
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x14(%rsp),%edi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
push   0x50(%rsp)
push   %r13
push   $0x0
push   $0x0
push   %rbx
push   %r14
call   1050 <gluBuild2DMipmapLevelsCore@plt>
add    $0x30,%rsp
jmp    11fd <gluBuild2DMipmaps+0xbd>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
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
define i32 @gluBuild2DMipmaps(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i8* %6, i8** %15
%21 = load i32, i32* %10
%22 = load i32, i32* %13
%23 = load i32, i32* %14
%24 = call i32 @checkMipmapArgs(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %20
%25 = load i32, i32* %20
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %7
%28 = load i32, i32* %20
store i32 %28, i32* %8
br label %66
29: ; preds = %7
%30 = load i32, i32* %11
%31 = icmp slt i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %12
%34 = icmp slt i32 %33, 1
br i1 %34, label %35, label %37
35: ; preds = %32, %29
%36 = load i32, i32* @GLU_INVALID_VALUE
store i32 %36, i32* %8
br label %66
37: ; preds = %32
%38 = load i32, i32* %9
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = load i32, i32* %10
%42 = load i32, i32* %13
%43 = load i32, i32* %14
%44 = call i32 @closestFit(i32 %38, i32 %39, i32 %40, i32 %41, i32 %42, i32 %43, i32* %16, i32* %17)
%45 = load i32, i32* %16
%46 = call i32 @computeLog(i32 %45)
store i32 %46, i32* %19
%47 = load i32, i32* %17
%48 = call i32 @computeLog(i32 %47)
store i32 %48, i32* %18
%49 = load i32, i32* %18
%50 = load i32, i32* %19
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %37
%53 = load i32, i32* %18
store i32 %53, i32* %19
br label %54
54: ; preds = %52, %37
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = load i32, i32* %11
%58 = load i32, i32* %12
%59 = load i32, i32* %16
%60 = load i32, i32* %17
%61 = load i32, i32* %13
%62 = load i32, i32* %14
%63 = load i32, i32* %19
%64 = load i8*, i8** %15
%65 = call i32 @gluBuild2DMipmapLevelsCore(i32 %55, i32 %56, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61, i32 %62, i32 0, i32 0, i32 %63, i8* %64)
store i32 %65, i32* %8
br label %66
66: ; preds = %54, %35, %27
%67 = load i32, i32* %8
ret i32 %67
}

LLVM IR (-O2):
@GLU_INVALID_VALUE = global i32 0
define i32 @gluBuild2DMipmaps(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = bitcast i32* %8 to i8*
%11 = bitcast i32* %9 to i8*
%12 = tail call i32 @checkMipmapArgs(i32 %1, i32 %4, i32 %5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %7
%15 = icmp slt i32 %2, 1
%16 = icmp slt i32 %3, 1
%17 = or i1 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* @GLU_INVALID_VALUE
br label %31
20: ; preds = %14
%21 = call i32 @closestFit(i32 %0, i32 %2, i32 %3, i32 %1, i32 %4, i32 %5, i32* %8, i32* %9)
%22 = load i32, i32* %8
%23 = call i32 @computeLog(i32 %22)
%24 = load i32, i32* %9
%25 = call i32 @computeLog(i32 %24)
%26 = icmp sgt i32 %25, %23
%27 = select i1 %26, i32 %25, i32 %23
%28 = load i32, i32* %8
%29 = load i32, i32* %9
%30 = call i32 @gluBuild2DMipmapLevelsCore(i32 %0, i32 %1, i32 %2, i32 %3, i32 %28, i32 %29, i32 %4, i32 %5, i32 0, i32 0, i32 %27, i8* %6)
br label %31
31: ; preds = %7, %20, %18
%32 = phi i32 [ %19, %18 ], [ %30, %20 ], [ %12, %7 ]
ret i32 %32
}