#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 /*<<< orphan*/ GLuint;
typedef int /*<<< orphan*/ GLsizei;
typedef int /*<<< orphan*/ GLint;
typedef char GLchar;

/* Variables and functions */
int /*<<< orphan*/ GL_LINK_STATUS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ glAttachShader_func(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ glCreateProgram_func();
int /*<<< orphan*/ glGetProgramInfoLog_func(int /*<<< orphan*/, int,
                                            int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ glGetProgramiv_func(int /*<<< orphan*/, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ glLinkProgram_func(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
GLuint LinkShaders(GLuint vertShader, GLuint fragShader) {
  GLuint program = glCreateProgram_func();
  glAttachShader_func(program, fragShader);
  glAttachShader_func(program, vertShader);
  glLinkProgram_func(program);
  {
    GLint stat;
    glGetProgramiv_func(program, GL_LINK_STATUS, &stat);
    if (!stat) {
      GLchar log[1000];
      GLsizei len;
      glGetProgramInfoLog_func(program, 1000, &len, log);
      fprintf(stderr, "Shader link error:\n%s\n", log);
      return 0;
    }
  }
  return program;
}


x86 assembly (clang, -O0):
<LinkShaders>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1070 <glCreateProgram_func@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <glAttachShader_func@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <glAttachShader_func@plt>
mov    -0x10(%rbp),%edi
call   1060 <glLinkProgram_func@plt>
mov    -0x10(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1080 <glGetProgramiv_func@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11fb <LinkShaders+0x9b>
mov    -0x10(%rbp),%edi
lea    -0x400(%rbp),%rcx
mov    $0x3e8,%esi
lea    -0x404(%rbp),%rdx
call   1030 <glGetProgramInfoLog_func@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    -0x400(%rbp),%rdx
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1201 <LinkShaders+0xa1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LinkShaders>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %esi,%ebx
mov    %edi,%r15d
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <glCreateProgram_func@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %ebx,%esi
call   1040 <glAttachShader_func@plt>
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <glAttachShader_func@plt>
mov    %ebp,%edi
call   1060 <glLinkProgram_func@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1080 <glGetProgramiv_func@plt>
cmpl   $0x0,0x8(%rsp)
je     11b9 <LinkShaders+0x59>
mov    %ebp,%r14d
jmp    11ea <LinkShaders+0x8a>
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    $0x3e8,%esi
mov    %rbx,%rcx
call   1030 <glGetProgramInfoLog_func@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %r14d,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GL_LINK_STATUS = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Shader link error:\0A%s\0A\00"
define i32 @LinkShaders(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = call i32 (...) @glCreateProgram_func()
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = call i32 @glAttachShader_func(i32 %11, i32 %12)
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = call i32 @glAttachShader_func(i32 %14, i32 %15)
%17 = load i32, i32* %6
%18 = call i32 @glLinkProgram_func(i32 %17)
%19 = load i32, i32* %6
%20 = load i32, i32* @GL_LINK_STATUS
%21 = call i32 @glGetProgramiv_func(i32 %19, i32 %20, i32* %7)
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %2
%25 = load i32, i32* %6
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%27 = call i32 @glGetProgramInfoLog_func(i32 %25, i32 1000, i32* %9, i8* %26)
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 0, i32* %3
br label %33
31: ; preds = %2
%32 = load i32, i32* %6
store i32 %32, i32* %3
br label %33
33: ; preds = %31, %24
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@GL_LINK_STATUS = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Shader link error:\0A%s\0A\00"
define i32 @LinkShaders(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = tail call i32 (...) @glCreateProgram_func()
%7 = tail call i32 @glAttachShader_func(i32 %6, i32 %1)
%8 = tail call i32 @glAttachShader_func(i32 %6, i32 %0)
%9 = tail call i32 @glLinkProgram_func(i32 %6)
%10 = bitcast i32* %3 to i8*
%11 = load i32, i32* @GL_LINK_STATUS
%12 = call i32 @glGetProgramiv_func(i32 %6, i32 %11, i32* %3)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%17 = bitcast i32* %5 to i8*
%18 = call i32 @glGetProgramInfoLog_func(i32 %6, i32 1000, i32* %5, i8* %16)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %21
21: ; preds = %2, %15
%22 = phi i32 [ %6, %2 ], [ 0, %15 ]
ret i32 %22
}