#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 Athena_Image {
  int dummy;
};

/* Variables and functions */
int Athena_LoadPNG(struct Athena_Image *, char const *);
int Athena_LoadTGA(struct Athena_Image *, char const *);
scalar_t__ memcmp(char const *, char *, int);
int strlen(char const *);
unsigned Athena_LoadAuto(struct Athena_Image *to, const char *path) {
  const char *const end = path + strlen(path), *str = end;
  while (str[0] != '.') {
    if (str == path)
      return 4u;
    str--;
  }
  if (end - str == 4) {
    if (memcmp(str, ".png", 4) == 0)
      return Athena_LoadPNG(to, path);
    else if (memcmp(str, ".tga", 4) == 0)
      return Athena_LoadTGA(to, path);
  }
  return 4u;
}


x86 assembly (clang, -O0):
<Athena_LoadAuto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11b4 <Athena_LoadAuto+0x74>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11a3 <Athena_LoadAuto+0x63>
movl   $0x4,-0x4(%rbp)
jmp    1242 <Athena_LoadAuto+0x102>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1179 <Athena_LoadAuto+0x39>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
jne    123b <Athena_LoadAuto+0xfb>
mov    -0x28(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    11fd <Athena_LoadAuto+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <Athena_LoadPNG@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <Athena_LoadAuto+0x102>
mov    -0x28(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    1231 <Athena_LoadAuto+0xf1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <Athena_LoadTGA@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <Athena_LoadAuto+0x102>
jmp    1236 <Athena_LoadAuto+0xf6>
jmp    123b <Athena_LoadAuto+0xfb>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Athena_LoadAuto>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    (%r15,%rcx,1),%rax
cmpb   $0x2e,(%r15,%rcx,1)
mov    %rax,%rbx
je     1187 <Athena_LoadAuto+0x47>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %rcx,%rcx
je     11c2 <Athena_LoadAuto+0x82>
lea    -0x1(%rcx),%rbx
cmpb   $0x2e,-0x1(%r15,%rcx,1)
mov    %rbx,%rcx
jne    1170 <Athena_LoadAuto+0x30>
add    %r15,%rbx
sub    %rbx,%rax
cmp    $0x4,%rax
jne    11c2 <Athena_LoadAuto+0x82>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11cd <Athena_LoadAuto+0x8d>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11dd <Athena_LoadAuto+0x9d>
mov    $0x4,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <Athena_LoadPNG@plt>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <Athena_LoadTGA@plt>

LLVM IR (-O0):
%struct.Athena_Image = type { i32 }
@.str = [5 x i8] c".png\00"
@.str.1 = [5 x i8] c".tga\00"
define i32 @Athena_LoadAuto(%struct.Athena_Image* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.Athena_Image*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store %struct.Athena_Image* %0, %struct.Athena_Image** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8* %12, i8** %6
%13 = load i8*, i8** %6
store i8* %13, i8** %7
br label %14
14: ; preds = %25, %2
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 46
br i1 %19, label %20, label %28
20: ; preds = %14
%21 = load i8*, i8** %7
%22 = load i8*, i8** %5
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 4, i32* %3
br label %54
25: ; preds = %20
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %7
br label %14
28: ; preds = %14
%29 = load i8*, i8** %6
%30 = load i8*, i8** %7
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = icmp eq i64 %33, 4
br i1 %34, label %35, label %53
35: ; preds = %28
%36 = load i8*, i8** %7
%37 = call i64 @memcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load %struct.Athena_Image*, %struct.Athena_Image** %4
%41 = load i8*, i8** %5
%42 = call i32 @Athena_LoadPNG(%struct.Athena_Image* %40, i8* %41)
store i32 %42, i32* %3
br label %54
43: ; preds = %35
%44 = load i8*, i8** %7
%45 = call i64 @memcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load %struct.Athena_Image*, %struct.Athena_Image** %4
%49 = load i8*, i8** %5
%50 = call i32 @Athena_LoadTGA(%struct.Athena_Image* %48, i8* %49)
store i32 %50, i32* %3
br label %54
51: ; preds = %43
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52, %28
store i32 4, i32* %3
br label %54
54: ; preds = %53, %47, %39, %24
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.Athena_Image = type { i32 }
@.str = [5 x i8] c".png\00"
@.str.1 = [5 x i8] c".tga\00"
define i32 @Athena_LoadAuto(%struct.Athena_Image* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 46
br i1 %7, label %15, label %8
8: ; preds = %2, %11
%9 = phi i8* [ %12, %11 ], [ %5, %2 ]
%10 = icmp eq i8* %9, %1
br i1 %10, label %31, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %8
15: ; preds = %11, %2
%16 = phi i8* [ %5, %2 ], [ %12, %11 ]
%17 = ptrtoint i8* %5 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = icmp eq i64 %19, 4
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = tail call i64 @memcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @Athena_LoadPNG(%struct.Athena_Image* %0, i8* %1)
br label %31
26: ; preds = %21
%27 = tail call i64 @memcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 @Athena_LoadTGA(%struct.Athena_Image* %0, i8* %1)
br label %31
31: ; preds = %8, %15, %26, %29, %24
%32 = phi i32 [ %25, %24 ], [ %30, %29 ], [ 4, %26 ], [ 4, %15 ], [ 4, %8 ]
ret i32 %32
}