#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 */
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int daemon_DataFileType(char *filename) {
  int len = strlen(filename);
  if (strcmp("gz", filename + len - 2) == 0) {
    return 1;
  }
  if (strcmp("zip", filename + len - 3) == 0) {
    return 2;
  }
  if (strcmp("deflate", filename + len - 7) == 0) {
    return 3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<daemon_DataFileType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffe,%rsi
lea    0xeb2(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1169 <daemon_DataFileType+0x49>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <daemon_DataFileType+0xb2>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffd,%rsi
lea    0xe84(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    119a <daemon_DataFileType+0x7a>
movl   $0x2,-0x4(%rbp)
jmp    11d2 <daemon_DataFileType+0xb2>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff9,%rsi
lea    0xe57(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11cb <daemon_DataFileType+0xab>
movl   $0x3,-0x4(%rbp)
jmp    11d2 <daemon_DataFileType+0xb2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<daemon_DataFileType>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%r14
lea    (%rbx,%r14,1),%rsi
add    $0xfffffffffffffffe,%rsi
lea    0xec2(%rip),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1180 <daemon_DataFileType+0x60>
add    %r14,%rbx
lea    -0x3(%rbx),%rsi
lea    0xead(%rip),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1187 <daemon_DataFileType+0x67>
add    $0xfffffffffffffff9,%rbx
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%eax
jmp    118c <daemon_DataFileType+0x6c>
mov    $0x1,%eax
jmp    118c <daemon_DataFileType+0x6c>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"gz\00"
@.str.1 = [4 x i8] c"zip\00"
@.str.2 = [8 x i8] c"deflate\00"
define i32 @daemon_DataFileType(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -2
%12 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %34
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -3
%21 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 2, i32* %2
br label %34
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 -7
%30 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 3, i32* %2
br label %34
33: ; preds = %24
store i32 0, i32* %2
br label %34
34: ; preds = %33, %32, %23, %14
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"gz\00"
@.str.1 = [4 x i8] c"zip\00"
@.str.2 = [8 x i8] c"deflate\00"
define i32 @daemon_DataFileType(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -2
%6 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %4, i64 -3
%10 = tail call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %4, i64 -7
%14 = tail call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 3, i32 0
br label %17
17: ; preds = %12, %8, %1
%18 = phi i32 [ 1, %1 ], [ 2, %8 ], [ %16, %12 ]
ret i32 %18
}