#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int detect_cycle(char *str_detect) {
  FILE *pFile;
  int detect_line_num = 1;
  int detect_find_result = 0;
  char detect_temp[512];
  pFile = fopen("/var/www/active_log.txt", "r");
  while ((fgets(detect_temp, 512, pFile) != NULL) &&
         (detect_find_result == 0)) {
    if ((strstr(detect_temp, str_detect)) != NULL) {
      detect_find_result++;
    }
    detect_line_num++;
  }
  fclose(pFile);
  return (detect_find_result);
}


x86 assembly (clang, -O0):
<detect_cycle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x221(%rbp)
je     11ab <detect_cycle+0x6b>
cmpl   $0x0,-0x18(%rbp)
sete   %al
mov    %al,-0x221(%rbp)
mov    -0x221(%rbp),%al
test   $0x1,%al
jne    11be <detect_cycle+0x7e>
jmp    11ef <detect_cycle+0xaf>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11e1 <detect_cycle+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <detect_cycle+0x34>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_cycle>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
lea    0xea7(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b3 <detect_cycle+0x73>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rbx,%rbx
jne    11a8 <detect_cycle+0x68>
test   %rax,%rax
jne    1180 <detect_cycle+0x40>
xor    %ebp,%ebp
test   %rbx,%rbx
setne  %bpl
jmp    11b5 <detect_cycle+0x75>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/var/www/active_log.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @detect_cycle(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
store i8* %0, i8** %2
store i32 1, i32* %4
store i32 0, i32* %5
%7 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
br label %8
8: ; preds = %26, %1
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %3
%11 = call i32* @fgets(i8* %9, i32 512, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %29
18: ; preds = %16
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %2
%21 = call i32* @strstr(i8* %19, i8* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %18
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %8
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/www/active_log.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @detect_cycle(i8* nocapture %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32* @fgets(i8* %3, i32 512, i32* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = call i32* @strstr(i8* %3, i8* dereferenceable(1) %0)
%9 = icmp ne i32* %8, null
%10 = call i32* @fgets(i8* %3, i32 512, i32* %4)
%11 = icmp eq i32* %10, null
%12 = or i1 %9, %11
br i1 %12, label %13, label %7
13: ; preds = %7
%14 = zext i1 %9 to i32
br label %15
15: ; preds = %13, %1
%16 = phi i32 [ 0, %1 ], [ %14, %13 ]
%17 = call i32 @fclose(i32* %4)
ret i32 %16
}