#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 */
int /*<<< orphan*/ memcpy(int *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ w_strlwr_n(char *, char *, int);
int FccTagForName(char *src) {
  char tfc[5];
  int v;
  char *s;
  s = src + strlen(src);
  while ((s > src) && (*s != '.'))
    s--;
  if (*s == '.') {
    w_strlwr_n(tfc, s + 1, 4);
    if (!strcmp(tfc, "wav"))
      return ((('W') | (('A') << 8) | (('V') << 16) | ((' ') << 24)));
    if (!strcmp(tfc, "bmp"))
      return ((('B') | (('M') << 8) | (('P') << 16) | ((' ') << 24)));
    if (!strcmp(tfc, "avi"))
      return ((('A') | (('V') << 8) | (('I') << 16) | ((' ') << 24)));
    if (!strcmp(tfc, "ico"))
      return ((('I') | (('C') << 8) | (('O') << 16) | ((' ') << 24)));
    memcpy(&v, tfc, 4);
    return (v);
  }
  return (0);
}


x86 assembly (clang, -O0):
<FccTagForName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x31(%rbp)
jbe    1190 <FccTagForName+0x50>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a0 <FccTagForName+0x60>
jmp    11b1 <FccTagForName+0x71>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    116d <FccTagForName+0x2d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1288 <FccTagForName+0x148>
lea    -0x15(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    $0x4,%edx
call   1060 <w_strlwr_n@plt>
lea    -0x15(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11fc <FccTagForName+0xbc>
movl   $0x20564157,-0x4(%rbp)
jmp    128f <FccTagForName+0x14f>
lea    -0x15(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1221 <FccTagForName+0xe1>
movl   $0x20504d42,-0x4(%rbp)
jmp    128f <FccTagForName+0x14f>
lea    -0x15(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1246 <FccTagForName+0x106>
movl   $0x20495641,-0x4(%rbp)
jmp    128f <FccTagForName+0x14f>
lea    -0x15(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    126b <FccTagForName+0x12b>
movl   $0x204f4349,-0x4(%rbp)
jmp    128f <FccTagForName+0x14f>
lea    -0x15(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <FccTagForName+0x14f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FccTagForName>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rsi
test   %eax,%eax
jle    115e <FccTagForName+0x2e>
nopw   0x0(%rax,%rax,1)
cmpb   $0x2e,(%rsi)
je     1165 <FccTagForName+0x35>
add    $0xffffffffffffffff,%rsi
cmp    %rbx,%rsi
ja     1150 <FccTagForName+0x20>
xor    %eax,%eax
cmpb   $0x2e,(%rsi)
jne    11d4 <FccTagForName+0xa4>
add    $0x1,%rsi
lea    0x7(%rsp),%rdi
mov    $0x4,%edx
call   1050 <w_strlwr_n@plt>
cmpl   $0x766177,0x7(%rsp)
je     11ba <FccTagForName+0x8a>
cmpl   $0x706d62,0x7(%rsp)
je     11c1 <FccTagForName+0x91>
cmpl   $0x697661,0x7(%rsp)
je     11c8 <FccTagForName+0x98>
cmpl   $0x6f6369,0x7(%rsp)
je     11cf <FccTagForName+0x9f>
lea    0xc(%rsp),%rdi
lea    0x7(%rsp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0xc(%rsp),%eax
jmp    11d4 <FccTagForName+0xa4>
mov    $0x20564157,%eax
jmp    11d4 <FccTagForName+0xa4>
mov    $0x20504d42,%eax
jmp    11d4 <FccTagForName+0xa4>
mov    $0x20495641,%eax
jmp    11d4 <FccTagForName+0xa4>
mov    $0x204f4349,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"wav\00"
@.str.1 = [4 x i8] c"bmp\00"
@.str.2 = [4 x i8] c"avi\00"
@.str.3 = [4 x i8] c"ico\00"
define i32 @FccTagForName(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [5 x i8]
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8* %11, i8** %6
br label %12
12: ; preds = %23, %1
%13 = load i8*, i8** %6
%14 = load i8*, i8** %3
%15 = icmp ugt i8* %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 46
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %6
br label %12
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 46
br i1 %30, label %31, label %59
31: ; preds = %26
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i32 @w_strlwr_n(i8* %32, i8* %34, i32 4)
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %31
store i32 542523735, i32* %2
br label %60
40: ; preds = %31
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
store i32 542133570, i32* %2
br label %60
45: ; preds = %40
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
store i32 541677121, i32* %2
br label %60
50: ; preds = %45
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %50
store i32 542065481, i32* %2
br label %60
55: ; preds = %50
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%57 = call i32 @memcpy(i32* %5, i8* %56, i32 4)
%58 = load i32, i32* %5
store i32 %58, i32* %2
br label %60
59: ; preds = %26
store i32 0, i32* %2
br label %60
60: ; preds = %59, %55, %54, %49, %44, %39
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@.str = [4 x i8] c"wav\00"
@.str.1 = [4 x i8] c"bmp\00"
@.str.2 = [4 x i8] c"avi\00"
@.str.3 = [4 x i8] c"ico\00"
define i32 @FccTagForName(i8* %0) {
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %17
10: ; preds = %1, %14
%11 = phi i8* [ %15, %14 ], [ %8, %1 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %11, i64 -1
%16 = icmp ugt i8* %15, %0
br i1 %16, label %10, label %17
17: ; preds = %14, %1
%18 = phi i8* [ %8, %1 ], [ %15, %14 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 46
br i1 %20, label %21, label %39
21: ; preds = %10, %17
%22 = phi i8* [ %18, %17 ], [ %11, %10 ]
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i32 @w_strlwr_n(i8* %4, i8* %23, i32 4)
%25 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %21
%28 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %27
%31 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 4)
%32 = icmp eq i32 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %30
%34 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = call i32 @memcpy(i32* %3, i8* %4, i32 4)
%38 = load i32, i32* %3
br label %39
39: ; preds = %17, %33, %30, %27, %21, %36
%40 = phi i32 [ %38, %36 ], [ 542523735, %21 ], [ 542133570, %27 ], [ 541677121, %30 ], [ 542065481, %33 ], [ 0, %17 ]
ret i32 %40
}