#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*/ strcmp(char const *, char *);
char *strrchr(char const *, char);
int check_ath_ko(unsigned char *elf_hdr, const char *filename) {
  const char *file = strrchr(filename, '/');
  if (!file)
    file = filename;
  else
    file++;
  return (!strcmp(file, "ath.ko") && elf_hdr[5] == 0x02 &&
          elf_hdr[18] == 0x00 && elf_hdr[19] == 0x08);
}


x86 assembly (clang, -O0):
<check_ath_ko>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <check_ath_ko+0x3a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <check_ath_ko+0x46>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    11c3 <check_ath_ko+0xa3>
mov    -0x8(%rbp),%rax
movzbl 0x5(%rax),%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
mov    %al,-0x19(%rbp)
jne    11c3 <check_ath_ko+0xa3>
mov    -0x8(%rbp),%rax
movzbl 0x12(%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
jne    11c3 <check_ath_ko+0xa3>
mov    -0x8(%rbp),%rax
movzbl 0x13(%rax),%eax
cmp    $0x8,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_ath_ko>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %rbx,%rdi
lea    0xeb7(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    116e <check_ath_ko+0x4e>
cmpb   $0x2,0x5(%r14)
jne    116e <check_ath_ko+0x4e>
cmpb   $0x0,0x12(%r14)
jne    116e <check_ath_ko+0x4e>
xor    %eax,%eax
cmpb   $0x8,0x13(%r14)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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