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

/* Variables and functions */
char *make_permenent_string(char *);
char *work_out_file_extension(unsigned char *header) {
  char *extension = NULL;
  if (header[0] == 'G' && header[1] == 'I' && header[2] == 'F' &&
      header[3] == '8') {
    extension = ".gif";
  } else if (header[0] == (unsigned char)0x89 &&
             header[1] == (unsigned char)0x50 &&
             header[2] == (unsigned char)0x4E &&
             header[3] == (unsigned char)0x47 &&
             header[4] == (unsigned char)0x0D &&
             header[5] == (unsigned char)0x0A &&
             header[6] == (unsigned char)0x1A &&
             header[7] == (unsigned char)0x0A) {
    extension = ".png";
  } else if (header[0] == (unsigned char)0xFF &&
             header[1] == (unsigned char)0xD8 &&
             header[2] == (unsigned char)0xFF) {
    if ((header[3] == (unsigned char)0xE0) ||
        (header[3] == (unsigned char)0xE1 && header[6] == 'E' &&
         header[7] == 'x' && header[8] == 'i' && header[9] == 'f' &&
         header[10] == 0)) {
      extension = ".jpeg";
    } else if (header[3] == (unsigned char)0xEE) {
      extension = ".jpg";
    }
  }
  if (extension != NULL) {
    extension = make_permenent_string(extension);
  }
  return extension;
}


x86 assembly (clang, -O0):
<work_out_file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x47,%eax
jne    1177 <work_out_file_extension+0x67>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x49,%eax
jne    1177 <work_out_file_extension+0x67>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x46,%eax
jne    1177 <work_out_file_extension+0x67>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x38,%eax
jne    1177 <work_out_file_extension+0x67>
lea    0xe92(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1305 <work_out_file_extension+0x1f5>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x89,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x50,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x4e,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x47,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0xd,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0xa,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x6(%rax),%eax
cmp    $0x1a,%eax
jne    1210 <work_out_file_extension+0x100>
mov    -0x8(%rbp),%rax
movzbl 0x7(%rax),%eax
cmp    $0xa,%eax
jne    1210 <work_out_file_extension+0x100>
lea    0xdfe(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1300 <work_out_file_extension+0x1f0>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    12fb <work_out_file_extension+0x1eb>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xd8,%eax
jne    12fb <work_out_file_extension+0x1eb>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0xff,%eax
jne    12fb <work_out_file_extension+0x1eb>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0xe0,%eax
je     12c3 <work_out_file_extension+0x1b3>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0xe1,%eax
jne    12d3 <work_out_file_extension+0x1c3>
mov    -0x8(%rbp),%rax
movzbl 0x6(%rax),%eax
cmp    $0x45,%eax
jne    12d3 <work_out_file_extension+0x1c3>
mov    -0x8(%rbp),%rax
movzbl 0x7(%rax),%eax
cmp    $0x78,%eax
jne    12d3 <work_out_file_extension+0x1c3>
mov    -0x8(%rbp),%rax
movzbl 0x8(%rax),%eax
cmp    $0x69,%eax
jne    12d3 <work_out_file_extension+0x1c3>
mov    -0x8(%rbp),%rax
movzbl 0x9(%rax),%eax
cmp    $0x66,%eax
jne    12d3 <work_out_file_extension+0x1c3>
mov    -0x8(%rbp),%rax
movzbl 0xa(%rax),%eax
cmp    $0x0,%eax
jne    12d3 <work_out_file_extension+0x1c3>
lea    0xd40(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    12f6 <work_out_file_extension+0x1e6>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0xee,%eax
jne    12f1 <work_out_file_extension+0x1e1>
lea    0xd23(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    12f6 <work_out_file_extension+0x1e6>
jmp    12fb <work_out_file_extension+0x1eb>
jmp    1300 <work_out_file_extension+0x1f0>
jmp    1305 <work_out_file_extension+0x1f5>
cmpq   $0x0,-0x10(%rbp)
je     131d <work_out_file_extension+0x20d>
mov    -0x10(%rbp),%rdi
call   1030 <make_permenent_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work_out_file_extension>:
mov    (%rdi),%al
cmp    $0x89,%al
je     113c <work_out_file_extension+0x2c>
cmp    $0xff,%al
je     1172 <work_out_file_extension+0x62>
cmp    $0x47,%al
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x49,0x1(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x46,0x2(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x38,0x3(%rdi)
jne    117e <work_out_file_extension+0x6e>
lea    0xec9(%rip),%rdi
jmp    1030 <make_permenent_string@plt>
cmpb   $0x50,0x1(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x4e,0x2(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x47,0x3(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0xd,0x4(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0xa,0x5(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x1a,0x6(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0xa,0x7(%rdi)
jne    117e <work_out_file_extension+0x6e>
lea    0xe98(%rip),%rdi
jmp    1030 <make_permenent_string@plt>
cmpb   $0xd8,0x1(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0xff,0x2(%rdi)
je     1181 <work_out_file_extension+0x71>
xor    %eax,%eax
ret
mov    0x3(%rdi),%cl
lea    0xe7f(%rip),%rax
cmp    $0xe0,%cl
je     11c1 <work_out_file_extension+0xb1>
cmp    $0xee,%cl
je     11ba <work_out_file_extension+0xaa>
cmp    $0xe1,%cl
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x45,0x6(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x78,0x7(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x69,0x8(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x66,0x9(%rdi)
jne    117e <work_out_file_extension+0x6e>
cmpb   $0x0,0xa(%rdi)
jne    117e <work_out_file_extension+0x6e>
jmp    11c1 <work_out_file_extension+0xb1>
lea    0xe4f(%rip),%rax
mov    %rax,%rdi
jmp    1030 <make_permenent_string@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".gif\00"
@.str.1 = [5 x i8] c".png\00"
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [5 x i8] c".jpg\00"
define i8* @work_out_file_extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
%8 = icmp eq i32 %7, 71
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 73
br i1 %14, label %15, label %28
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 70
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 56
br i1 %26, label %27, label %28
27: ; preds = %21
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
br label %149
28: ; preds = %21, %15, %9, %1
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 137
br i1 %33, label %34, label %77
34: ; preds = %28
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 80
br i1 %39, label %40, label %77
40: ; preds = %34
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = icmp eq i32 %44, 78
br i1 %45, label %46, label %77
46: ; preds = %40
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i64 3
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 71
br i1 %51, label %52, label %77
52: ; preds = %46
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i64 4
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp eq i32 %56, 13
br i1 %57, label %58, label %77
58: ; preds = %52
%59 = load i8*, i8** %2
%60 = getelementptr inbounds i8, i8* %59, i64 5
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %62, 10
br i1 %63, label %64, label %77
64: ; preds = %58
%65 = load i8*, i8** %2
%66 = getelementptr inbounds i8, i8* %65, i64 6
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = icmp eq i32 %68, 26
br i1 %69, label %70, label %77
70: ; preds = %64
%71 = load i8*, i8** %2
%72 = getelementptr inbounds i8, i8* %71, i64 7
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = icmp eq i32 %74, 10
br i1 %75, label %76, label %77
76: ; preds = %70
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %148
77: ; preds = %70, %64, %58, %52, %46, %40, %34, %28
%78 = load i8*, i8** %2
%79 = getelementptr inbounds i8, i8* %78, i64 0
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = icmp eq i32 %81, 255
br i1 %82, label %83, label %147
83: ; preds = %77
%84 = load i8*, i8** %2
%85 = getelementptr inbounds i8, i8* %84, i64 1
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %87, 216
br i1 %88, label %89, label %147
89: ; preds = %83
%90 = load i8*, i8** %2
%91 = getelementptr inbounds i8, i8* %90, i64 2
%92 = load i8, i8* %91
%93 = zext i8 %92 to i32
%94 = icmp eq i32 %93, 255
br i1 %94, label %95, label %147
95: ; preds = %89
%96 = load i8*, i8** %2
%97 = getelementptr inbounds i8, i8* %96, i64 3
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = icmp eq i32 %99, 224
br i1 %100, label %137, label %101
101: ; preds = %95
%102 = load i8*, i8** %2
%103 = getelementptr inbounds i8, i8* %102, i64 3
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = icmp eq i32 %105, 225
br i1 %106, label %107, label %138
107: ; preds = %101
%108 = load i8*, i8** %2
%109 = getelementptr inbounds i8, i8* %108, i64 6
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = icmp eq i32 %111, 69
br i1 %112, label %113, label %138
113: ; preds = %107
%114 = load i8*, i8** %2
%115 = getelementptr inbounds i8, i8* %114, i64 7
%116 = load i8, i8* %115
%117 = zext i8 %116 to i32
%118 = icmp eq i32 %117, 120
br i1 %118, label %119, label %138
119: ; preds = %113
%120 = load i8*, i8** %2
%121 = getelementptr inbounds i8, i8* %120, i64 8
%122 = load i8, i8* %121
%123 = zext i8 %122 to i32
%124 = icmp eq i32 %123, 105
br i1 %124, label %125, label %138
125: ; preds = %119
%126 = load i8*, i8** %2
%127 = getelementptr inbounds i8, i8* %126, i64 9
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = icmp eq i32 %129, 102
br i1 %130, label %131, label %138
131: ; preds = %125
%132 = load i8*, i8** %2
%133 = getelementptr inbounds i8, i8* %132, i64 10
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = icmp eq i32 %135, 0
br i1 %136, label %137, label %138
137: ; preds = %131, %95
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %146
138: ; preds = %131, %125, %119, %113, %107, %101
%139 = load i8*, i8** %2
%140 = getelementptr inbounds i8, i8* %139, i64 3
%141 = load i8, i8* %140
%142 = zext i8 %141 to i32
%143 = icmp eq i32 %142, 238
br i1 %143, label %144, label %145
144: ; preds = %138
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %145
145: ; preds = %144, %138
br label %146
146: ; preds = %145, %137
br label %147
147: ; preds = %146, %89, %83, %77
br label %148
148: ; preds = %147, %76
br label %149
149: ; preds = %148, %27
%150 = load i8*, i8** %3
%151 = icmp ne i8* %150, null
br i1 %151, label %152, label %155
152: ; preds = %149
%153 = load i8*, i8** %3
%154 = call i8* @make_permenent_string(i8* %153)
store i8* %154, i8** %3
br label %155
155: ; preds = %152, %149
%156 = load i8*, i8** %3
ret i8* %156
}

LLVM IR (-O2):
@.str = [5 x i8] c".gif\00"
@.str.1 = [5 x i8] c".png\00"
@.str.2 = [6 x i8] c".jpeg\00"
@.str.3 = [5 x i8] c".jpg\00"
define i8* @work_out_file_extension(i8* %0) {
%2 = load i8, i8* %0
switch i8 %2, label %78 [
i8 71, label %3
i8 -119, label %15
i8 -1, label %43
]
3: ; preds = %1
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 73
br i1 %6, label %7, label %78
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 70
br i1 %10, label %11, label %78
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 56
br i1 %14, label %75, label %78
15: ; preds = %1
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 80
br i1 %18, label %19, label %78
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %0, i64 2
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 78
br i1 %22, label %23, label %78
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %0, i64 3
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 71
br i1 %26, label %27, label %78
27: ; preds = %23
%28 = getelementptr inbounds i8, i8* %0, i64 4
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 13
br i1 %30, label %31, label %78
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %0, i64 5
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %78
35: ; preds = %31
%36 = getelementptr inbounds i8, i8* %0, i64 6
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 26
br i1 %38, label %39, label %78
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %0, i64 7
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 10
br i1 %42, label %75, label %78
43: ; preds = %1
%44 = getelementptr inbounds i8, i8* %0, i64 1
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, -40
br i1 %46, label %47, label %78
47: ; preds = %43
%48 = getelementptr inbounds i8, i8* %0, i64 2
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, -1
br i1 %50, label %51, label %78
51: ; preds = %47
%52 = getelementptr inbounds i8, i8* %0, i64 3
%53 = load i8, i8* %52
switch i8 %53, label %78 [
i8 -32, label %75
i8 -31, label %54
i8 -18, label %74
]
54: ; preds = %51
%55 = getelementptr inbounds i8, i8* %0, i64 6
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 69
br i1 %57, label %58, label %78
58: ; preds = %54
%59 = getelementptr inbounds i8, i8* %0, i64 7
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 120
br i1 %61, label %62, label %78
62: ; preds = %58
%63 = getelementptr inbounds i8, i8* %0, i64 8
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 105
br i1 %65, label %66, label %78
66: ; preds = %62
%67 = getelementptr inbounds i8, i8* %0, i64 9
%68 = load i8, i8* %67
%69 = icmp eq i8 %68, 102
br i1 %69, label %70, label %78
70: ; preds = %66
%71 = getelementptr inbounds i8, i8* %0, i64 10
%72 = load i8, i8* %71
%73 = icmp eq i8 %72, 0
br i1 %73, label %75, label %78
74: ; preds = %51
br label %75
75: ; preds = %51, %74, %70, %39, %11
%76 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %70 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %51 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %39 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %74 ]
%77 = tail call i8* @make_permenent_string(i8* %76)
br label %78
78: ; preds = %51, %1, %70, %66, %62, %58, %54, %3, %7, %11, %15, %19, %23, %27, %31, %35, %39, %43, %47, %75
%79 = phi i8* [ %77, %75 ], [ null, %47 ], [ null, %43 ], [ null, %39 ], [ null, %35 ], [ null, %31 ], [ null, %27 ], [ null, %23 ], [ null, %19 ], [ null, %15 ], [ null, %11 ], [ null, %7 ], [ null, %3 ], [ null, %54 ], [ null, %58 ], [ null, %62 ], [ null, %66 ], [ null, %70 ], [ null, %1 ], [ null, %51 ]
ret i8* %79
}