#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 */
typedef int /*<<< orphan*/ filetypes;

/* Variables and functions */
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ to_lower(char *);
int supported_filetype(const char *filetype, const int no_png,
                       int *png_refused) {
  static const char *filetypes[] = {
      "bmp", "emf", "eps", "gif", "pcx", "png", "svg", "tif", "txt",
  };
  char lc_filetype[4] = {0};
  int i;
  if (png_refused) {
    *png_refused = 0;
  }
  strncpy(lc_filetype, filetype, 3);
  to_lower(lc_filetype);
  if (no_png && strcmp(lc_filetype, "png") == 0) {
    if (png_refused) {
      *png_refused = 1;
    }
    return 0;
  }
  for (i = 0; i < ((int)(sizeof(filetypes) / sizeof((filetypes)[0]))); i++) {
    if (strcmp(lc_filetype, filetypes[i]) == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<supported_filetype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
je     1178 <supported_filetype+0x38>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x24(%rbp),%rdi
call   1040 <to_lower@plt>
cmpl   $0x0,-0x14(%rbp)
je     11d8 <supported_filetype+0x98>
lea    -0x24(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d8 <supported_filetype+0x98>
cmpq   $0x0,-0x20(%rbp)
je     11cc <supported_filetype+0x8c>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1231 <supported_filetype+0xf1>
movl   $0x0,-0x28(%rbp)
cmpl   $0x9,-0x28(%rbp)
jge    122a <supported_filetype+0xea>
lea    -0x24(%rbp),%rdi
movslq -0x28(%rbp),%rcx
lea    0x2e58(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1217 <supported_filetype+0xd7>
movl   $0x1,-0x4(%rbp)
jmp    1231 <supported_filetype+0xf1>
jmp    121c <supported_filetype+0xdc>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11df <supported_filetype+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<supported_filetype>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rsi
movl   $0x0,0xc(%rsp)
test   %rdx,%rdx
je     1154 <supported_filetype+0x24>
movl   $0x0,(%rbx)
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1040 <to_lower@plt>
test   %r14d,%r14d
je     118d <supported_filetype+0x5d>
lea    0xe9a(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     126e <supported_filetype+0x13e>
lea    0xe6c(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xe51(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xe3b(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xe25(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xe0f(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xdfd(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xdeb(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xdd9(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     127b <supported_filetype+0x14b>
lea    0xdc7(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    127b <supported_filetype+0x14b>
xor    %ebp,%ebp
test   %rbx,%rbx
je     127b <supported_filetype+0x14b>
movl   $0x1,(%rbx)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@supported_filetype.filetypes = internal global [9 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0)]
@.str = [4 x i8] c"bmp\00"
@.str.1 = [4 x i8] c"emf\00"
@.str.2 = [4 x i8] c"eps\00"
@.str.3 = [4 x i8] c"gif\00"
@.str.4 = [4 x i8] c"pcx\00"
@.str.5 = [4 x i8] c"png\00"
@.str.6 = [4 x i8] c"svg\00"
@.str.7 = [4 x i8] c"tif\00"
@.str.8 = [4 x i8] c"txt\00"
define i32 @supported_filetype(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [4 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = bitcast [4 x i8]* %8 to i8*
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32*, i32** %7
store i32 0, i32* %14
br label %15
15: ; preds = %13, %3
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 3)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%20 = call i32 @to_lower(i8* %19)
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, 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 %33
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32*, i32** %7
store i32 1, i32* %31
br label %32
32: ; preds = %30, %27
store i32 0, i32* %4
br label %51
33: ; preds = %23, %15
store i32 0, i32* %9
br label %34
34: ; preds = %47, %33
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 9
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [9 x i8*], [9 x i8*]* @supported_filetype.filetypes, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %38, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
store i32 1, i32* %4
br label %51
46: ; preds = %37
br label %47
47: ; preds = %46
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %34
50: ; preds = %34
store i32 0, i32* %4
br label %51
51: ; preds = %50, %45, %32
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@.str = [4 x i8] c"bmp\00"
@.str.1 = [4 x i8] c"emf\00"
@.str.2 = [4 x i8] c"eps\00"
@.str.3 = [4 x i8] c"gif\00"
@.str.4 = [4 x i8] c"pcx\00"
@.str.5 = [4 x i8] c"png\00"
@.str.6 = [4 x i8] c"svg\00"
@.str.7 = [4 x i8] c"tif\00"
@.str.8 = [4 x i8] c"txt\00"
define i32 @supported_filetype(i8* %0, i32 %1, i32* writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = icmp eq i32* %2, null
br i1 %6, label %8, label %7
7: ; preds = %3
store i32 0, i32* %2
br label %8
8: ; preds = %7, %3
%9 = call i32 @strncpy(i8* %5, i8* %0, i32 3)
%10 = call i32 @to_lower(i8* %5)
%11 = icmp eq i32 %1, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
br i1 %6, label %45, label %16
16: ; preds = %15
store i32 1, i32* %2
br label %45
17: ; preds = %12, %8
%18 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %45, label %20
20: ; preds = %17
%21 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %45, label %23
23: ; preds = %20
%24 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %45, label %26
26: ; preds = %23
%27 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %45, label %29
29: ; preds = %26
%30 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %45, label %32
32: ; preds = %29
%33 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %32
%36 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %41, %17, %20, %23, %26, %29, %32, %35, %38, %15, %16
%46 = phi i32 [ 0, %16 ], [ 0, %15 ], [ 1, %17 ], [ 1, %20 ], [ 1, %23 ], [ 1, %26 ], [ 1, %29 ], [ 1, %32 ], [ 1, %35 ], [ 1, %38 ], [ %44, %41 ]
ret i32 %46
}