#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 /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
int is_torrent_file(char *fn) {
  char *ext = ".torrent";
  char *ptr = fn;
  int is_torrent = 0;
  while (strstr(ptr, ext)) {
    ptr = strstr(ptr, ext);
    if (strcmp(ptr, ext) == 0) {
      is_torrent = 1;
      break;
    }
    ptr += strlen(ext);
  }
  return is_torrent;
}


x86 assembly (clang, -O0):
<is_torrent_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11bf <is_torrent_file+0x8f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a1 <is_torrent_file+0x71>
movl   $0x1,-0x1c(%rbp)
jmp    11bf <is_torrent_file+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1156 <is_torrent_file+0x26>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_torrent_file>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rsi
call   1050 <strstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1198 <is_torrent_file+0x68>
mov    %rax,%rbx
lea    0xeae(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1192 <is_torrent_file+0x62>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <is_torrent_file+0x30>
jmp    1198 <is_torrent_file+0x68>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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