#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 *);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
int is_driftnet_file(char *filename) {
  if (strncmp(filename, "driftnet-", 9) != 0)
    return 0;
  char *p = strrchr(filename, '.');
  if (p == 0)
    return 0;
  return (strcmp(p, ".jpeg") == 0 || strcmp(p, ".gif") == 0 ||
          strcmp(p, ".png") == 0 || strcmp(p, ".mp3") == 0);
}


x86 assembly (clang, -O0):
<is_driftnet_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1167 <is_driftnet_file+0x37>
movl   $0x0,-0x4(%rbp)
jmp    121b <is_driftnet_file+0xeb>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <is_driftnet_file+0x60>
movl   $0x0,-0x4(%rbp)
jmp    121b <is_driftnet_file+0xeb>
mov    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1210 <is_driftnet_file+0xe0>
mov    -0x18(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1210 <is_driftnet_file+0xe0>
mov    -0x18(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1210 <is_driftnet_file+0xe0>
mov    -0x18(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_driftnet_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xec2(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1156 <is_driftnet_file+0x26>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     114f <is_driftnet_file+0x1f>
mov    %rax,%r14
lea    0xe98(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     114f <is_driftnet_file+0x1f>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     114f <is_driftnet_file+0x1f>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     114f <is_driftnet_file+0x1f>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    114f <is_driftnet_file+0x1f>

LLVM IR (-O0):
@.str = [10 x i8] c"driftnet-\00"
@.str.1 = [6 x i8] c".jpeg\00"
@.str.2 = [5 x i8] c".gif\00"
@.str.3 = [5 x i8] c".png\00"
@.str.4 = [5 x i8] c".mp3\00"
define i32 @is_driftnet_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %34
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* %2
br label %34
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br label %31
31: ; preds = %27, %23, %19, %15
%32 = phi i1 [ true, %23 ], [ true, %19 ], [ true, %15 ], [ %30, %27 ]
%33 = zext i1 %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %31, %14, %8
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"driftnet-\00"
@.str.1 = [6 x i8] c".jpeg\00"
@.str.2 = [5 x i8] c".gif\00"
@.str.3 = [5 x i8] c".png\00"
@.str.4 = [5 x i8] c".mp3\00"
define i32 @is_driftnet_file(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %4, %16, %13, %10, %7, %1
%21 = phi i32 [ 0, %1 ], [ 0, %4 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ], [ %19, %16 ]
ret i32 %21
}