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


x86 assembly (clang, -O0):
<gluBuild1DMipmapLevels>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <checkMipmapArgs@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     118d <gluBuild1DMipmapLevels+0x4d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1224 <gluBuild1DMipmapLevels+0xe4>
cmpl   $0x1,-0x18(%rbp)
jge    11a8 <gluBuild1DMipmapLevels+0x68>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    1224 <gluBuild1DMipmapLevels+0xe4>
mov    -0x18(%rbp),%edi
call   1050 <computeLog@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    0x10(%rbp),%esi
mov    0x18(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1030 <isLegalLevels@plt>
cmp    $0x0,%eax
jne    11e7 <gluBuild1DMipmapLevels+0xa7>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    1224 <gluBuild1DMipmapLevels+0xe4>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x24(%rbp),%ebx
mov    0x10(%rbp),%r11d
mov    0x18(%rbp),%r10d
mov    0x20(%rbp),%rax
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <gluBuild1DMipmapLevelsCore@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild1DMipmapLevels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8d,%r12d
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r13d
mov    %esi,%edi
mov    %ecx,%esi
mov    %r8d,%edx
call   1040 <checkMipmapArgs@plt>
test   %eax,%eax
jne    11c5 <gluBuild1DMipmapLevels+0x85>
test   %r15d,%r15d
jle    11bc <gluBuild1DMipmapLevels+0x7c>
mov    %r15d,%edi
call   1050 <computeLog@plt>
lea    (%rax,%r14,1),%ecx
mov    %r14d,%edi
mov    0x40(%rsp),%esi
mov    0x48(%rsp),%edx
call   1030 <isLegalLevels@plt>
test   %eax,%eax
je     11bc <gluBuild1DMipmapLevels+0x7c>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %r12d,%r9d
push   0x50(%rsp)
mov    0x50(%rsp),%eax
push   %rax
mov    0x50(%rsp),%eax
push   %rax
push   %r14
call   1060 <gluBuild1DMipmapLevelsCore@plt>
add    $0x28,%rsp
jmp    11c9 <gluBuild1DMipmapLevels+0x89>
mov    0x2e25(%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 @gluBuild1DMipmapLevels(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i8* %8) {
%10 = alloca i32
%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 i8*
%20 = alloca i32
%21 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i8* %8, i8** %19
%22 = load i32, i32* %12
%23 = load i32, i32* %14
%24 = load i32, i32* %15
%25 = call i32 @checkMipmapArgs(i32 %22, i32 %23, i32 %24)
store i32 %25, i32* %21
%26 = load i32, i32* %21
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %9
%29 = load i32, i32* %21
store i32 %29, i32* %10
br label %61
30: ; preds = %9
%31 = load i32, i32* %13
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* @GLU_INVALID_VALUE
store i32 %34, i32* %10
br label %61
35: ; preds = %30
%36 = load i32, i32* %13
%37 = call i32 @computeLog(i32 %36)
store i32 %37, i32* %20
%38 = load i32, i32* %16
%39 = load i32, i32* %20
%40 = add nsw i32 %39, %38
store i32 %40, i32* %20
%41 = load i32, i32* %16
%42 = load i32, i32* %17
%43 = load i32, i32* %18
%44 = load i32, i32* %20
%45 = call i32 @isLegalLevels(i32 %41, i32 %42, i32 %43, i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %35
%48 = load i32, i32* @GLU_INVALID_VALUE
store i32 %48, i32* %10
br label %61
49: ; preds = %35
%50 = load i32, i32* %11
%51 = load i32, i32* %12
%52 = load i32, i32* %13
%53 = load i32, i32* %13
%54 = load i32, i32* %14
%55 = load i32, i32* %15
%56 = load i32, i32* %16
%57 = load i32, i32* %17
%58 = load i32, i32* %18
%59 = load i8*, i8** %19
%60 = call i32 @gluBuild1DMipmapLevelsCore(i32 %50, i32 %51, i32 %52, i32 %53, i32 %54, i32 %55, i32 %56, i32 %57, i32 %58, i8* %59)
store i32 %60, i32* %10
br label %61
61: ; preds = %49, %47, %33, %28
%62 = load i32, i32* %10
ret i32 %62
}

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