#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 computeLog(int);
int gluBuild2DMipmapLevelsCore(int /*<<< orphan*/, int, int, int, int, int,
                               int /*<<< orphan*/, int /*<<< orphan*/, int, int,
                               int, void const *);
int /*<<< orphan*/ isLegalLevels(int, int, int, int);
GLint gluBuild2DMipmapLevels(GLenum target, GLint internalFormat, GLsizei width,
                             GLsizei height, 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) {
    return GLU_INVALID_VALUE;
  }
  levels = computeLog(width);
  level = computeLog(height);
  if (level > levels)
    levels = level;
  levels += userLevel;
  if (!isLegalLevels(userLevel, baseLevel, maxLevel, levels))
    return GLU_INVALID_VALUE;
  return gluBuild2DMipmapLevelsCore(target, internalFormat, width, height,
                                    width, height, format, type, userLevel,
                                    baseLevel, maxLevel, data);
}


x86 assembly (clang, -O0):
<gluBuild2DMipmapLevels>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    %edx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1040 <checkMipmapArgs@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     1194 <gluBuild2DMipmapLevels+0x54>
mov    -0x40(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1264 <gluBuild2DMipmapLevels+0x124>
cmpl   $0x1,-0x28(%rbp)
jl     11a8 <gluBuild2DMipmapLevels+0x68>
cmpl   $0x1,-0x2c(%rbp)
jge    11b9 <gluBuild2DMipmapLevels+0x79>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1264 <gluBuild2DMipmapLevels+0x124>
mov    -0x28(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    11e1 <gluBuild2DMipmapLevels+0xa1>
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x10(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x10(%rbp),%edi
mov    0x18(%rbp),%esi
mov    0x20(%rbp),%edx
mov    -0x3c(%rbp),%ecx
call   1030 <isLegalLevels@plt>
cmp    $0x0,%eax
jne    1215 <gluBuild2DMipmapLevels+0xd5>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1264 <gluBuild2DMipmapLevels+0x124>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r15d
mov    -0x34(%rbp),%r14d
mov    0x10(%rbp),%ebx
mov    0x18(%rbp),%r11d
mov    0x20(%rbp),%r10d
mov    0x28(%rbp),%rax
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1060 <gluBuild2DMipmapLevelsCore@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild2DMipmapLevels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r12d
mov    %r8d,%r14d
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%r13d
mov    %esi,%edi
mov    %r8d,%esi
mov    %r9d,%edx
call   1040 <checkMipmapArgs@plt>
test   %eax,%eax
jne    11ea <gluBuild2DMipmapLevels+0xaa>
test   %r15d,%r15d
jle    11e1 <gluBuild2DMipmapLevels+0xa1>
test   %ebp,%ebp
jle    11e1 <gluBuild2DMipmapLevels+0xa1>
mov    %r13d,0x4(%rsp)
mov    %r15d,%edi
call   1050 <computeLog@plt>
mov    %eax,%r13d
mov    %ebp,%edi
call   1050 <computeLog@plt>
cmp    %r13d,%eax
cmovg  %eax,%r13d
mov    0x40(%rsp),%edi
add    %edi,%r13d
mov    0x48(%rsp),%esi
mov    0x50(%rsp),%edx
mov    %r13d,%ecx
call   1030 <isLegalLevels@plt>
test   %eax,%eax
je     11e1 <gluBuild2DMipmapLevels+0xa1>
mov    0x4(%rsp),%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %ebp,%r9d
push   0x58(%rsp)
mov    0x58(%rsp),%eax
push   %rax
mov    0x58(%rsp),%eax
push   %rax
mov    0x58(%rsp),%eax
push   %rax
push   %r12
push   %r14
call   1060 <gluBuild2DMipmapLevelsCore@plt>
add    $0x38,%rsp
jmp    11ee <gluBuild2DMipmapLevels+0xae>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
add    $0x8,%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 @gluBuild2DMipmapLevels(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i8* %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
store i32 %0, i32* %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store i32 %6, i32* %18
store i32 %7, i32* %19
store i32 %8, i32* %20
store i8* %9, i8** %21
%25 = load i32, i32* %13
%26 = load i32, i32* %16
%27 = load i32, i32* %17
%28 = call i32 @checkMipmapArgs(i32 %25, i32 %26, i32 %27)
store i32 %28, i32* %24
%29 = load i32, i32* %24
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %10
%32 = load i32, i32* %24
store i32 %32, i32* %11
br label %77
33: ; preds = %10
%34 = load i32, i32* %14
%35 = icmp slt i32 %34, 1
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %15
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %36, %33
%40 = load i32, i32* @GLU_INVALID_VALUE
store i32 %40, i32* %11
br label %77
41: ; preds = %36
%42 = load i32, i32* %14
%43 = call i32 @computeLog(i32 %42)
store i32 %43, i32* %23
%44 = load i32, i32* %15
%45 = call i32 @computeLog(i32 %44)
store i32 %45, i32* %22
%46 = load i32, i32* %22
%47 = load i32, i32* %23
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %41
%50 = load i32, i32* %22
store i32 %50, i32* %23
br label %51
51: ; preds = %49, %41
%52 = load i32, i32* %18
%53 = load i32, i32* %23
%54 = add nsw i32 %53, %52
store i32 %54, i32* %23
%55 = load i32, i32* %18
%56 = load i32, i32* %19
%57 = load i32, i32* %20
%58 = load i32, i32* %23
%59 = call i32 @isLegalLevels(i32 %55, i32 %56, i32 %57, i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %51
%62 = load i32, i32* @GLU_INVALID_VALUE
store i32 %62, i32* %11
br label %77
63: ; preds = %51
%64 = load i32, i32* %12
%65 = load i32, i32* %13
%66 = load i32, i32* %14
%67 = load i32, i32* %15
%68 = load i32, i32* %14
%69 = load i32, i32* %15
%70 = load i32, i32* %16
%71 = load i32, i32* %17
%72 = load i32, i32* %18
%73 = load i32, i32* %19
%74 = load i32, i32* %20
%75 = load i8*, i8** %21
%76 = call i32 @gluBuild2DMipmapLevelsCore(i32 %64, i32 %65, i32 %66, i32 %67, i32 %68, i32 %69, i32 %70, i32 %71, i32 %72, i32 %73, i32 %74, i8* %75)
store i32 %76, i32* %11
br label %77
77: ; preds = %63, %61, %39, %31
%78 = load i32, i32* %11
ret i32 %78
}

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