#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 */
struct imgImage {
  int dummy;
};

/* Variables and functions */
int imgReadImgBmp(char const *, struct imgImage *);
int imgReadImgPng(char const *, struct imgImage *);
int imgReadImgTga(char const *, struct imgImage *);
int imgReadFile(struct imgImage *img, const char *fn) {
  int err = -1;
  if ((err = imgReadImgPng(fn, img)) == 0)
    return err;
  if ((err = imgReadImgTga(fn, img)) == 0)
    return err;
  if ((err = imgReadImgBmp(fn, img)) == 0)
    return err;
  return err;
}


x86 assembly (clang, -O0):
<imgReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <imgReadImgPng@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    116b <imgReadFile+0x3b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <imgReadFile+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <imgReadImgTga@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    118f <imgReadFile+0x5f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <imgReadFile+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <imgReadImgBmp@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11b3 <imgReadFile+0x83>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <imgReadFile+0x89>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imgReadFile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <imgReadImgPng@plt>
test   %eax,%eax
je     116a <imgReadFile+0x3a>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <imgReadImgTga@plt>
test   %eax,%eax
je     116a <imgReadFile+0x3a>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <imgReadImgBmp@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.imgImage = type { i32 }
define i32 @imgReadFile(%struct.imgImage* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.imgImage*
%5 = alloca i8*
%6 = alloca i32
store %struct.imgImage* %0, %struct.imgImage** %4
store i8* %1, i8** %5
store i32 -1, i32* %6
%7 = load i8*, i8** %5
%8 = load %struct.imgImage*, %struct.imgImage** %4
%9 = call i32 @imgReadImgPng(i8* %7, %struct.imgImage* %8)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %6
store i32 %12, i32* %3
br label %29
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load %struct.imgImage*, %struct.imgImage** %4
%16 = call i32 @imgReadImgTga(i8* %14, %struct.imgImage* %15)
store i32 %16, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32, i32* %6
store i32 %19, i32* %3
br label %29
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load %struct.imgImage*, %struct.imgImage** %4
%23 = call i32 @imgReadImgBmp(i8* %21, %struct.imgImage* %22)
store i32 %23, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %29
27: ; preds = %20
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %25, %18, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.imgImage = type { i32 }
define i32 @imgReadFile(%struct.imgImage* %0, i8* %1) {
%3 = tail call i32 @imgReadImgPng(i8* %1, %struct.imgImage* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @imgReadImgTga(i8* %1, %struct.imgImage* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @imgReadImgBmp(i8* %1, %struct.imgImage* %0)
br label %10
10: ; preds = %8, %5, %2
%11 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %9, %8 ]
ret i32 %11
}