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

/* Variables and functions */
struct image *image_from_jpeg(unsigned char const *, size_t);
struct image *image_from_ktx(unsigned char const *, size_t);
struct image *image_from_png(unsigned char const *, size_t);
struct image *image_from_tga(unsigned char const *, size_t);
struct image *image_from_tiff(unsigned char const *, size_t);
scalar_t__ strcmpi(char const *, char *);
struct image *image_from_mem_buf(const unsigned char *data, size_t sz,
                                 const char *hint) {
  if (strcmpi(hint, "png") == 0) {
    return image_from_png(data, sz);
  } else if (strcmpi(hint, "jpg") == 0 || strcmpi(hint, "jpeg") == 0) {
    return image_from_jpeg(data, sz);
  } else if (strcmpi(hint, "tif") == 0 || strcmpi(hint, "tiff") == 0) {
    return image_from_tiff(data, sz);
  } else if (strcmpi(hint, "tga") == 0) {
    return image_from_tga(data, sz);
  } else if (strcmpi(hint, "ktx") == 0) {
    return image_from_ktx(data, sz);
  }
  return 0;
}


x86 assembly (clang, -O0):
<image_from_mem_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    11a4 <image_from_mem_buf+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <image_from_png@plt>
mov    %rax,-0x8(%rbp)
jmp    12b4 <image_from_mem_buf+0x154>
mov    -0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
je     11d8 <image_from_mem_buf+0x78>
mov    -0x20(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    11ee <image_from_mem_buf+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <image_from_jpeg@plt>
mov    %rax,-0x8(%rbp)
jmp    12b4 <image_from_mem_buf+0x154>
mov    -0x20(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
je     1222 <image_from_mem_buf+0xc2>
mov    -0x20(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    1238 <image_from_mem_buf+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <image_from_tiff@plt>
mov    %rax,-0x8(%rbp)
jmp    12b4 <image_from_mem_buf+0x154>
mov    -0x20(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    1268 <image_from_mem_buf+0x108>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <image_from_tga@plt>
mov    %rax,-0x8(%rbp)
jmp    12b4 <image_from_mem_buf+0x154>
mov    -0x20(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    1298 <image_from_mem_buf+0x138>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <image_from_ktx@plt>
mov    %rax,-0x8(%rbp)
jmp    12b4 <image_from_mem_buf+0x154>
jmp    129d <image_from_mem_buf+0x13d>
jmp    12a2 <image_from_mem_buf+0x142>
jmp    12a7 <image_from_mem_buf+0x147>
jmp    12ac <image_from_mem_buf+0x14c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<image_from_mem_buf>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8b(%rip),%rsi
mov    %rdx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1216 <image_from_mem_buf+0xb6>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1206 <image_from_mem_buf+0xa6>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1206 <image_from_mem_buf+0xa6>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1226 <image_from_mem_buf+0xc6>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1226 <image_from_mem_buf+0xc6>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1236 <image_from_mem_buf+0xd6>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     1246 <image_from_mem_buf+0xe6>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <image_from_jpeg@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <image_from_png@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <image_from_tiff@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <image_from_tga@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <image_from_ktx@plt>

LLVM IR (-O0):
%struct.image = type { i32 }
@.str = [4 x i8] c"png\00"
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [5 x i8] c"jpeg\00"
@.str.3 = [4 x i8] c"tif\00"
@.str.4 = [5 x i8] c"tiff\00"
@.str.5 = [4 x i8] c"tga\00"
@.str.6 = [4 x i8] c"ktx\00"
define %struct.image* @image_from_mem_buf(i8* %0, i64 %1, i8* %2) {
%4 = alloca %struct.image*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%8 = load i8*, i8** %7
%9 = call i64 @strcmpi(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call %struct.image* @image_from_png(i8* %12, i64 %13)
store %struct.image* %14, %struct.image** %4
br label %60
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = call i64 @strcmpi(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = call i64 @strcmpi(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19, %15
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = call %struct.image* @image_from_jpeg(i8* %24, i64 %25)
store %struct.image* %26, %struct.image** %4
br label %60
27: ; preds = %19
%28 = load i8*, i8** %7
%29 = call i64 @strcmpi(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %7
%33 = call i64 @strcmpi(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %31, %27
%36 = load i8*, i8** %5
%37 = load i64, i64* %6
%38 = call %struct.image* @image_from_tiff(i8* %36, i64 %37)
store %struct.image* %38, %struct.image** %4
br label %60
39: ; preds = %31
%40 = load i8*, i8** %7
%41 = call i64 @strcmpi(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i8*, i8** %5
%45 = load i64, i64* %6
%46 = call %struct.image* @image_from_tga(i8* %44, i64 %45)
store %struct.image* %46, %struct.image** %4
br label %60
47: ; preds = %39
%48 = load i8*, i8** %7
%49 = call i64 @strcmpi(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = load i64, i64* %6
%54 = call %struct.image* @image_from_ktx(i8* %52, i64 %53)
store %struct.image* %54, %struct.image** %4
br label %60
55: ; preds = %47
br label %56
56: ; preds = %55
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
store %struct.image* null, %struct.image** %4
br label %60
60: ; preds = %59, %51, %43, %35, %23, %11
%61 = load %struct.image*, %struct.image** %4
ret %struct.image* %61
}

LLVM IR (-O2):
%struct.image = type { i32 }
@.str = [4 x i8] c"png\00"
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [5 x i8] c"jpeg\00"
@.str.3 = [4 x i8] c"tif\00"
@.str.4 = [5 x i8] c"tiff\00"
@.str.5 = [4 x i8] c"tga\00"
@.str.6 = [4 x i8] c"ktx\00"
define %struct.image* @image_from_mem_buf(i8* %0, i64 %1, i8* %2) {
%4 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call %struct.image* @image_from_png(i8* %0, i64 %1)
br label %34
8: ; preds = %3
%9 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %8
%15 = tail call %struct.image* @image_from_jpeg(i8* %0, i64 %1)
br label %34
16: ; preds = %11
%17 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19, %16
%23 = tail call %struct.image* @image_from_tiff(i8* %0, i64 %1)
br label %34
24: ; preds = %19
%25 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call %struct.image* @image_from_tga(i8* %0, i64 %1)
br label %34
29: ; preds = %24
%30 = tail call i64 @strcmpi(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call %struct.image* @image_from_ktx(i8* %0, i64 %1)
br label %34
34: ; preds = %29, %32, %27, %22, %14, %6
%35 = phi %struct.image* [ %7, %6 ], [ %15, %14 ], [ %23, %22 ], [ %28, %27 ], [ %33, %32 ], [ null, %29 ]
ret %struct.image* %35
}