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

/* Variables and functions */
struct bitmap *bitmap_load_bmp(char const *);
struct bitmap *bitmap_load_pcx(char const *);
struct bitmap *bitmap_load_raw(char const *);
struct bitmap *bitmap_load_sgi_rgb(char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strrchr(char const *, char);
struct bitmap *bitmap_load_any(const char *path) {
  char *tail = strrchr(path, '.');
  if (!tail) {
    printf("bitmap: cannot determine type of %s\n", path);
    return 0;
  }
  tail++;
  if (!strcmp(tail, "raw")) {
    return bitmap_load_raw(path);
  } else if (!strcmp(tail, "bmp") || !strcmp(tail, "BMP")) {
    return bitmap_load_bmp(path);
  } else if (!strcmp(tail, "pcx") || !strcmp(tail, "PCX")) {
    return bitmap_load_pcx(path);
  } else if (!strcmp(tail, "rgb") || !strcmp(tail, "RGB")) {
    return bitmap_load_sgi_rgb(path);
  } else {
    printf("bitmap: bitmap type %s not supported.\n", tail);
    return 0;
  }
}


x86 assembly (clang, -O0):
<bitmap_load_any>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <bitmap_load_any+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12d1 <bitmap_load_any+0x161>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11ed <bitmap_load_any+0x7d>
mov    -0x10(%rbp),%rdi
call   1080 <bitmap_load_raw@plt>
mov    %rax,-0x8(%rbp)
jmp    12d1 <bitmap_load_any+0x161>
mov    -0x18(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     121f <bitmap_load_any+0xaf>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1231 <bitmap_load_any+0xc1>
mov    -0x10(%rbp),%rdi
call   1090 <bitmap_load_bmp@plt>
mov    %rax,-0x8(%rbp)
jmp    12d1 <bitmap_load_any+0x161>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1263 <bitmap_load_any+0xf3>
mov    -0x18(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1275 <bitmap_load_any+0x105>
mov    -0x10(%rbp),%rdi
call   1060 <bitmap_load_pcx@plt>
mov    %rax,-0x8(%rbp)
jmp    12d1 <bitmap_load_any+0x161>
mov    -0x18(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12a7 <bitmap_load_any+0x137>
mov    -0x18(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12b9 <bitmap_load_any+0x149>
mov    -0x10(%rbp),%rdi
call   1050 <bitmap_load_sgi_rgb@plt>
mov    %rax,-0x8(%rbp)
jmp    12d1 <bitmap_load_any+0x161>
mov    -0x18(%rbp),%rsi
lea    0xd7d(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_load_any>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     122a <bitmap_load_any+0xba>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1252 <bitmap_load_any+0xe2>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1243 <bitmap_load_any+0xd3>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1243 <bitmap_load_any+0xd3>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1261 <bitmap_load_any+0xf1>
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1261 <bitmap_load_any+0xf1>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1270 <bitmap_load_any+0x100>
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1270 <bitmap_load_any+0x100>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
jmp    1234 <bitmap_load_any+0xc4>
lea    0xdcf(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <bitmap_load_bmp@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <bitmap_load_raw@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <bitmap_load_pcx@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <bitmap_load_sgi_rgb@plt>

LLVM IR (-O0):
%struct.bitmap = type { i32 }
@.str = [37 x i8] c"bitmap: cannot determine type of %s\0A\00"
@.str.1 = [4 x i8] c"raw\00"
@.str.2 = [4 x i8] c"bmp\00"
@.str.3 = [4 x i8] c"BMP\00"
@.str.4 = [4 x i8] c"pcx\00"
@.str.5 = [4 x i8] c"PCX\00"
@.str.6 = [4 x i8] c"rgb\00"
@.str.7 = [4 x i8] c"RGB\00"
@.str.8 = [39 x i8] c"bitmap: bitmap type %s not supported.\0A\00"
define %struct.bitmap* @bitmap_load_any(i8* %0) {
%2 = alloca %struct.bitmap*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strrchr(i8* %5, i8 signext 46)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %10)
store %struct.bitmap* null, %struct.bitmap** %2
br label %57
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i8*, i8** %3
%20 = call %struct.bitmap* @bitmap_load_raw(i8* %19)
store %struct.bitmap* %20, %struct.bitmap** %2
br label %57
21: ; preds = %12
%22 = load i8*, i8** %4
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25, %21
%30 = load i8*, i8** %3
%31 = call %struct.bitmap* @bitmap_load_bmp(i8* %30)
store %struct.bitmap* %31, %struct.bitmap** %2
br label %57
32: ; preds = %25
%33 = load i8*, i8** %4
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36, %32
%41 = load i8*, i8** %3
%42 = call %struct.bitmap* @bitmap_load_pcx(i8* %41)
store %struct.bitmap* %42, %struct.bitmap** %2
br label %57
43: ; preds = %36
%44 = load i8*, i8** %4
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i8*, i8** %4
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %47, %43
%52 = load i8*, i8** %3
%53 = call %struct.bitmap* @bitmap_load_sgi_rgb(i8* %52)
store %struct.bitmap* %53, %struct.bitmap** %2
br label %57
54: ; preds = %47
%55 = load i8*, i8** %4
%56 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %55)
store %struct.bitmap* null, %struct.bitmap** %2
br label %57
57: ; preds = %54, %51, %40, %29, %18, %9
%58 = load %struct.bitmap*, %struct.bitmap** %2
ret %struct.bitmap* %58
}

LLVM IR (-O2):
%struct.bitmap = type { i32 }
@.str = [37 x i8] c"bitmap: cannot determine type of %s\0A\00"
@.str.1 = [4 x i8] c"raw\00"
@.str.2 = [4 x i8] c"bmp\00"
@.str.3 = [4 x i8] c"BMP\00"
@.str.4 = [4 x i8] c"pcx\00"
@.str.5 = [4 x i8] c"PCX\00"
@.str.6 = [4 x i8] c"rgb\00"
@.str.7 = [4 x i8] c"RGB\00"
@.str.8 = [39 x i8] c"bitmap: bitmap type %s not supported.\0A\00"
define %struct.bitmap* @bitmap_load_any(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %38
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %2, i64 1
%8 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call %struct.bitmap* @bitmap_load_raw(i8* %0)
br label %38
12: ; preds = %6
%13 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %12
%19 = tail call %struct.bitmap* @bitmap_load_bmp(i8* %0)
br label %38
20: ; preds = %15
%21 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23, %20
%27 = tail call %struct.bitmap* @bitmap_load_pcx(i8* %0)
br label %38
28: ; preds = %23
%29 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31, %28
%35 = tail call %struct.bitmap* @bitmap_load_sgi_rgb(i8* %0)
br label %38
36: ; preds = %31
%37 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %7)
br label %38
38: ; preds = %36, %34, %26, %18, %10, %4
%39 = phi %struct.bitmap* [ null, %36 ], [ %35, %34 ], [ %27, %26 ], [ %19, %18 ], [ %11, %10 ], [ null, %4 ]
ret %struct.bitmap* %39
}