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


x86 assembly (clang, -O0):
<gluBuild1DMipmaps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <checkMipmapArgs@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1182 <gluBuild1DMipmaps+0x42>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <gluBuild1DMipmaps+0xd4>
cmpl   $0x1,-0x10(%rbp)
jge    119d <gluBuild1DMipmaps+0x5d>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1214 <gluBuild1DMipmaps+0xd4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    $0x1,%edx
lea    -0x24(%rbp),%r10
lea    -0x2c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <closestFit@plt>
mov    -0x24(%rbp),%edi
call   1040 <computeLog@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
mov    -0x28(%rbp),%r10d
mov    -0x20(%rbp),%rax
xor    %r11d,%r11d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1060 <gluBuild1DMipmapLevelsCore@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gluBuild1DMipmaps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
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   1030 <checkMipmapArgs@plt>
test   %eax,%eax
jne    11cb <gluBuild1DMipmaps+0x8b>
test   %r15d,%r15d
jle    11c2 <gluBuild1DMipmaps+0x82>
lea    0x4(%rsp),%rax
mov    %rsp,%r10
mov    %r13d,%edi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %r12d,%r9d
push   %rax
push   %r10
call   1050 <closestFit@plt>
add    $0x10,%rsp
mov    (%rsp),%edi
call   1040 <computeLog@plt>
mov    (%rsp),%ecx
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %ebx,%r8d
mov    %r12d,%r9d
push   %r14
push   %rax
push   $0x0
push   $0x0
call   1060 <gluBuild1DMipmapLevelsCore@plt>
add    $0x20,%rsp
jmp    11cb <gluBuild1DMipmaps+0x8b>
mov    0x2e1f(%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 @gluBuild1DMipmaps(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%18 = load i32, i32* %9
%19 = load i32, i32* %11
%20 = load i32, i32* %12
%21 = call i32 @checkMipmapArgs(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %17
%22 = load i32, i32* %17
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = load i32, i32* %17
store i32 %25, i32* %7
br label %49
26: ; preds = %6
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* @GLU_INVALID_VALUE
store i32 %30, i32* %7
br label %49
31: ; preds = %26
%32 = load i32, i32* %8
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = load i32, i32* %11
%36 = load i32, i32* %12
%37 = call i32 @closestFit(i32 %32, i32 %33, i32 1, i32 %34, i32 %35, i32 %36, i32* %14, i32* %16)
%38 = load i32, i32* %14
%39 = call i32 @computeLog(i32 %38)
store i32 %39, i32* %15
%40 = load i32, i32* %8
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = load i32, i32* %14
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = load i32, i32* %15
%47 = load i8*, i8** %13
%48 = call i32 @gluBuild1DMipmapLevelsCore(i32 %40, i32 %41, i32 %42, i32 %43, i32 %44, i32 %45, i32 0, i32 0, i32 %46, i8* %47)
store i32 %48, i32* %7
br label %49
49: ; preds = %31, %29, %24
%50 = load i32, i32* %7
ret i32 %50
}

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