#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 scalar_t__ (*PFNGLGETSTRINGIPROC)(int /*<<< orphan*/, scalar_t__);
typedef int /*<<< orphan*/ GLubyte;
typedef scalar_t__ GLint;

/* Variables and functions */
int /*<<< orphan*/ GL_EXTENSIONS;
int /*<<< orphan*/ GL_NUM_EXTENSIONS;
int /*<<< orphan*/ glGetIntegerv(int /*<<< orphan*/, scalar_t__ *);
scalar_t__ glXGetProcAddressARB(int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *build_core_profile_extension_list(void) {
  GLint i, n, totalLen;
  char *buffer;
  static PFNGLGETSTRINGIPROC glGetStringi_func = NULL;
  if (!glGetStringi_func) {
    glGetStringi_func =
        (PFNGLGETSTRINGIPROC)glXGetProcAddressARB((GLubyte *)"glGetStringi");
  }
  glGetIntegerv(GL_NUM_EXTENSIONS, &n);
  totalLen = 0;
  for (i = 0; i < n; i++) {
    const char *ext = (const char *)glGetStringi_func(GL_EXTENSIONS, i);
    totalLen += strlen(ext) + 1;
  }
  buffer = malloc(totalLen + 1);
  if (buffer) {
    int pos = 0;
    for (i = 0; i < n; i++) {
      const char *ext = (const char *)glGetStringi_func(GL_EXTENSIONS, i);
      strcpy(buffer + pos, ext);
      pos += strlen(ext);
      buffer[pos++] = ' ';
    }
    buffer[pos] = '\0';
  }
  return buffer;
}


x86 assembly (clang, -O0):
<build_core_profile_extension_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
cmpq   $0x0,0x2ef0(%rip)
jne    1179 <build_core_profile_extension_list+0x29>
lea    0xe93(%rip),%rdi
call   1070 <glXGetProcAddressARB@plt>
mov    %rax,0x2ed7(%rip)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <glGetIntegerv@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11e9 <build_core_profile_extension_list+0x99>
mov    0x2ea0(%rip),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%edi
mov    -0x8(%rbp),%rsi
call   *%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119b <build_core_profile_extension_list+0x4b>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1299 <build_core_profile_extension_list+0x149>
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    128d <build_core_profile_extension_list+0x13d>
mov    0x2e27(%rip),%rax
mov    0x2da8(%rip),%rcx
mov    (%rcx),%edi
mov    -0x8(%rbp),%rsi
call   *%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1214 <build_core_profile_extension_list+0xc4>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_core_profile_extension_list>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmpq   $0x0,0x2eeb(%rip)
jne    117a <build_core_profile_extension_list+0x2a>
lea    0xe92(%rip),%rdi
call   1070 <glXGetProcAddressARB@plt>
mov    %rax,0x2ed6(%rip)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <glGetIntegerv@plt>
mov    0x8(%rsp),%r15
test   %r15,%r15
jle    11e0 <build_core_profile_extension_list+0x90>
xor    %ebx,%ebx
mov    0x2e38(%rip),%r12
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
mov    %rbx,%rsi
call   *0x2e93(%rip)
mov    %rax,%rdi
call   1040 <strlen@plt>
add    %rax,%r14
add    $0x1,%r14
add    $0x1,%rbx
mov    0x8(%rsp),%r15
cmp    %r15,%rbx
jl     11b0 <build_core_profile_extension_list+0x60>
add    $0x1,%r14
jmp    11e6 <build_core_profile_extension_list+0x96>
mov    $0x1,%r14d
mov    %r14,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1259 <build_core_profile_extension_list+0x109>
test   %r15,%r15
jle    1251 <build_core_profile_extension_list+0x101>
xor    %ebx,%ebx
mov    0x2dd4(%rip),%r12
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %rbx,%rsi
call   *0x2e33(%rip)
mov    %rax,%r15
lea    (%r14,%r13,1),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %r13,%rax
cltq
movb   $0x20,(%r14,%rax,1)
add    $0x1,%rbx
add    $0x1,%eax
movslq %eax,%r13
cmp    0x8(%rsp),%rbx
jl     1210 <build_core_profile_extension_list+0xc0>
jmp    1254 <build_core_profile_extension_list+0x104>
xor    %r13d,%r13d
movb   $0x0,(%r14,%r13,1)
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@build_core_profile_extension_list.glGetStringi_func = internal global i64 (i32, i64)* null
@.str = [13 x i8] c"glGetStringi\00"
@GL_NUM_EXTENSIONS = global i32 0
@GL_EXTENSIONS = global i32 0
define i8* @build_core_profile_extension_list() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%9 = icmp ne i64 (i32, i64)* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i64 @glXGetProcAddressARB(i32* bitcast ([13 x i8]* @.str to i32*))
%12 = inttoptr i64 %11 to i64 (i32, i64)*
store i64 (i32, i64)* %12, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
br label %13
13: ; preds = %10, %0
%14 = load i32, i32* @GL_NUM_EXTENSIONS
%15 = call i32 @glGetIntegerv(i32 %14, i64* %2)
store i64 0, i64* %3
store i64 0, i64* %1
br label %16
16: ; preds = %31, %13
%17 = load i64, i64* %1
%18 = load i64, i64* %2
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%22 = load i32, i32* @GL_EXTENSIONS
%23 = load i64, i64* %1
%24 = call i64 %21(i32 %22, i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = load i64, i64* %3
%30 = add nsw i64 %29, %28
store i64 %30, i64* %3
br label %31
31: ; preds = %20
%32 = load i64, i64* %1
%33 = add nsw i64 %32, 1
store i64 %33, i64* %1
br label %16
34: ; preds = %16
%35 = load i64, i64* %3
%36 = add nsw i64 %35, 1
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %4
%38 = load i8*, i8** %4
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %76
40: ; preds = %34
store i32 0, i32* %6
store i64 0, i64* %1
br label %41
41: ; preds = %68, %40
%42 = load i64, i64* %1
%43 = load i64, i64* %2
%44 = icmp slt i64 %42, %43
br i1 %44, label %45, label %71
45: ; preds = %41
%46 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%47 = load i32, i32* @GL_EXTENSIONS
%48 = load i64, i64* %1
%49 = call i64 %46(i32 %47, i64 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %7
%51 = load i8*, i8** %4
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8*, i8** %7
%56 = call i32 @strcpy(i8* %54, i8* %55)
%57 = load i8*, i8** %7
%58 = call i64 @strlen(i8* %57)
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = add nsw i64 %60, %58
%62 = trunc i64 %61 to i32
store i32 %62, i32* %6
%63 = load i8*, i8** %4
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 32, i8* %67
br label %68
68: ; preds = %45
%69 = load i64, i64* %1
%70 = add nsw i64 %69, 1
store i64 %70, i64* %1
br label %41
71: ; preds = %41
%72 = load i8*, i8** %4
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %71, %34
%77 = load i8*, i8** %4
ret i8* %77
}

LLVM IR (-O2):
@build_core_profile_extension_list.glGetStringi_func = internal unnamed_addr global i64 (i32, i64)* null
@.str = [13 x i8] c"glGetStringi\00"
@GL_NUM_EXTENSIONS = global i32 0
@GL_EXTENSIONS = global i32 0
define i8* @build_core_profile_extension_list() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%4 = icmp eq i64 (i32, i64)* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i64 @glXGetProcAddressARB(i32* bitcast ([13 x i8]* @.str to i32*))
%7 = inttoptr i64 %6 to i64 (i32, i64)*
store i64 (i32, i64)* %7, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
br label %8
8: ; preds = %5, %0
%9 = load i32, i32* @GL_NUM_EXTENSIONS
%10 = call i32 @glGetIntegerv(i32 %9, i64* %1)
%11 = load i64, i64* %1
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %8, %13
%14 = phi i64 [ %23, %13 ], [ 0, %8 ]
%15 = phi i64 [ %22, %13 ], [ 0, %8 ]
%16 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%17 = load i32, i32* @GL_EXTENSIONS
%18 = call i64 %16(i32 %17, i64 %14)
%19 = inttoptr i64 %18 to i8*
%20 = call i64 @strlen(i8* dereferenceable(1) %19)
%21 = add i64 %15, 1
%22 = add i64 %21, %20
%23 = add nuw nsw i64 %14, 1
%24 = load i64, i64* %1
%25 = icmp slt i64 %23, %24
br i1 %25, label %13, label %26
26: ; preds = %13
%27 = add i64 %22, 1
br label %28
28: ; preds = %26, %8
%29 = phi i64 [ %11, %8 ], [ %24, %26 ]
%30 = phi i64 [ 1, %8 ], [ %27, %26 ]
%31 = call i8* @malloc(i64 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %57, label %33
33: ; preds = %28
%34 = icmp sgt i64 %29, 0
br i1 %34, label %35, label %54
35: ; preds = %33, %35
%36 = phi i64 [ %49, %35 ], [ 0, %33 ]
%37 = phi i64 [ %51, %35 ], [ 0, %33 ]
%38 = load i64 (i32, i64)*, i64 (i32, i64)** @build_core_profile_extension_list.glGetStringi_func
%39 = load i32, i32* @GL_EXTENSIONS
%40 = call i64 %38(i32 %39, i64 %36)
%41 = inttoptr i64 %40 to i8*
%42 = getelementptr inbounds i8, i8* %31, i64 %37
%43 = call i32 @strcpy(i8* %42, i8* %41)
%44 = call i64 @strlen(i8* dereferenceable(1) %41)
%45 = add nsw i64 %44, %37
%46 = shl i64 %45, 32
%47 = ashr exact i64 %46, 32
%48 = getelementptr inbounds i8, i8* %31, i64 %47
store i8 32, i8* %48
%49 = add nuw nsw i64 %36, 1
%50 = add i64 %46, 4294967296
%51 = ashr exact i64 %50, 32
%52 = load i64, i64* %1
%53 = icmp slt i64 %49, %52
br i1 %53, label %35, label %54
54: ; preds = %35, %33
%55 = phi i64 [ 0, %33 ], [ %51, %35 ]
%56 = getelementptr inbounds i8, i8* %31, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %54, %28
ret i8* %31
}