#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*/ GLubyte;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ read_texture(char *, int *, int *, int *);
int /*<<< orphan*/ stderr;
void imgLoad(char *filename_in, int *w_out, int *h_out, GLubyte **img_out) {
  int comp;
  *img_out = (GLubyte *)read_texture(filename_in, w_out, h_out, &comp);
  if (*img_out == NULL) {
    fprintf(stderr, "unable to read %s\n", filename_in);
    exit(1);
  }
  if (comp != 3 && comp != 4) {
    fprintf(stderr, "%s: image is not RGB or RGBA\n", filename_in);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<imgLoad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x24(%rbp),%rcx
call   1040 <read_texture@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1198 <imgLoad+0x68>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x3,-0x24(%rbp)
je     11cf <imgLoad+0x9f>
cmpl   $0x4,-0x24(%rbp)
je     11cf <imgLoad+0x9f>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imgLoad>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%rcx
call   1040 <read_texture@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1160 <imgLoad+0x30>
mov    0x4(%rsp),%eax
add    $0xfffffffb,%eax
cmp    $0xfffffffd,%eax
jbe    1172 <imgLoad+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
jmp    1182 <imgLoad+0x52>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"unable to read %s\0A\00"
@.str.1 = [30 x i8] c"%s: image is not RGB or RGBA\0A\00"
define void @imgLoad(i8* %0, i32* %1, i32* %2, i32** %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32**
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32** %3, i32*** %8
%10 = load i8*, i8** %5
%11 = load i32*, i32** %6
%12 = load i32*, i32** %7
%13 = call i64 @read_texture(i8* %10, i32* %11, i32* %12, i32* %9)
%14 = inttoptr i64 %13 to i32*
%15 = load i32**, i32*** %8
store i32* %14, i32** %15
%16 = load i32**, i32*** %8
%17 = load i32*, i32** %16
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %5
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %4
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 3
br i1 %26, label %27, label %35
27: ; preds = %24
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 4
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %5
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27, %24
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"unable to read %s\0A\00"
@.str.1 = [30 x i8] c"%s: image is not RGB or RGBA\0A\00"
define void @imgLoad(i8* %0, i32* %1, i32* %2, i32** nocapture writeonly %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i64 @read_texture(i8* %0, i32* %1, i32* %2, i32* %5)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %3
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = load i32, i32* %5
%16 = add i32 %15, -5
%17 = icmp ult i32 %16, -2
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
ret void
}