#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 const *, char *);
char *strrchr(char const *, char);
int sources_type(char const *link) {
  char const *s;
  if (NULL == link)
    return -1;
  s = strrchr(link, '.');
  if (NULL == s)
    return -2;
  s += 1;
  if (0 == strcmp(s, "png") || 0 == strcmp(s, "jpg")) {
    return 0;
  } else if (0 == strcmp(s, "doc") || 0 == strcmp(s, "docx")) {
    return 1;
  } else if (0 == strcmp(s, "xls") || 0 == strcmp(s, "xlsx")) {
    return 2;
  } else if (0 == strcmp(s, "ppt") || 0 == strcmp(s, "pptx")) {
    return 3;
  } else if (0 == strcmp(s, "pdf"))
    return 4;
  else
    return -2;
}


x86 assembly (clang, -O0):
<sources_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1144 <sources_type+0x24>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    116e <sources_type+0x4e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11b6 <sources_type+0x96>
mov    -0x18(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11c2 <sources_type+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11fe <sources_type+0xde>
mov    -0x18(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    120a <sources_type+0xea>
movl   $0x1,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x18(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1246 <sources_type+0x126>
mov    -0x18(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1252 <sources_type+0x132>
movl   $0x2,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x18(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     128e <sources_type+0x16e>
mov    -0x18(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    129a <sources_type+0x17a>
movl   $0x3,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
mov    -0x18(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12c4 <sources_type+0x1a4>
movl   $0x4,-0x4(%rbp)
jmp    12cb <sources_type+0x1ab>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sources_type>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1228 <sources_type+0x108>
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     122f <sources_type+0x10f>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    $0x3,%ebp
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1234 <sources_type+0x114>
lea    0xe15(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
mov    $0x4,%eax
mov    $0xfffffffe,%ebp
cmove  %eax,%ebp
jmp    1234 <sources_type+0x114>
mov    $0xffffffff,%ebp
jmp    1234 <sources_type+0x114>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"png\00"
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [4 x i8] c"doc\00"
@.str.3 = [5 x i8] c"docx\00"
@.str.4 = [4 x i8] c"xls\00"
@.str.5 = [5 x i8] c"xlsx\00"
@.str.6 = [4 x i8] c"ppt\00"
@.str.7 = [5 x i8] c"pptx\00"
@.str.8 = [4 x i8] c"pdf\00"
define i32 @sources_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* null, %5
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %58
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i8* @strrchr(i8* %9, i8 signext 46)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* null, %11
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 -2, i32* %2
br label %58
14: ; preds = %8
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 0, %18
br i1 %19, label %24, label %20
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 0, %22
br i1 %23, label %24, label %25
24: ; preds = %20, %14
store i32 0, i32* %2
br label %58
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 0, %27
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %34
33: ; preds = %29, %25
store i32 1, i32* %2
br label %58
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 0, %36
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i8*, i8** %4
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = icmp eq i64 0, %40
br i1 %41, label %42, label %43
42: ; preds = %38, %34
store i32 2, i32* %2
br label %58
43: ; preds = %38
%44 = load i8*, i8** %4
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp eq i64 0, %45
br i1 %46, label %51, label %47
47: ; preds = %43
%48 = load i8*, i8** %4
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%50 = icmp eq i64 0, %49
br i1 %50, label %51, label %52
51: ; preds = %47, %43
store i32 3, i32* %2
br label %58
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%55 = icmp eq i64 0, %54
br i1 %55, label %56, label %57
56: ; preds = %52
store i32 4, i32* %2
br label %58
57: ; preds = %52
store i32 -2, i32* %2
br label %58
58: ; preds = %57, %56, %51, %42, %33, %24, %13, %7
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [4 x i8] c"png\00"
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [4 x i8] c"doc\00"
@.str.3 = [5 x i8] c"docx\00"
@.str.4 = [4 x i8] c"xls\00"
@.str.5 = [5 x i8] c"xlsx\00"
@.str.6 = [4 x i8] c"ppt\00"
@.str.7 = [5 x i8] c"pptx\00"
@.str.8 = [4 x i8] c"pdf\00"
define i32 @sources_type(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %35, label %3
3: ; preds = %1
%4 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %35, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %6
%11 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %35, label %13
13: ; preds = %10
%14 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %13
%17 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %35, label %19
19: ; preds = %16
%20 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %35, label %22
22: ; preds = %19
%23 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %35, label %25
25: ; preds = %22
%26 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %25
%29 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i32 4, i32 -2
br label %35
35: ; preds = %31, %25, %28, %19, %22, %13, %16, %6, %10, %3, %1
%36 = phi i32 [ -1, %1 ], [ -2, %3 ], [ 0, %10 ], [ 0, %6 ], [ 1, %16 ], [ 1, %13 ], [ 2, %22 ], [ 2, %19 ], [ 3, %28 ], [ 3, %25 ], [ %34, %31 ]
ret i32 %36
}