#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *get_cycle_number(char *cycle_str, char *cycle_num) {
  FILE *pFile;
  int cycle_line_num = 1;
  int cycle_find_result = 0;
  char cycle_temp[512];
  char str[100];
  char space[] = " ";
  int line_length;
  int start_point = -1;
  int num_length;
  pFile = fopen("/var/www/active_log.txt", "r");
  if (pFile != NULL) {
    while ((fgets(cycle_temp, 512, pFile) != NULL) &&
           (cycle_find_result == 0)) {
      if ((strstr(cycle_temp, cycle_str)) != NULL) {
        start_point =
            strstr(cycle_temp, cycle_str) - cycle_temp + strlen(cycle_str);
        num_length = 1;
        if (cycle_temp[start_point + 1] == space[0])
          num_length = 1;
        else if (cycle_temp[start_point + 2] == space[0])
          num_length = 2;
        else if (cycle_temp[start_point + 3] == space[0])
          num_length = 3;
        else if (cycle_temp[start_point + 4] == space[0])
          num_length = 4;
        else if (cycle_temp[start_point + 5] == space[0])
          num_length = 5;
        strncpy(cycle_num, &cycle_temp[start_point], num_length);
        cycle_num[num_length] = '\0';
        cycle_find_result++;
      } else {
        cycle_num[1] = '\0';
        strncpy(cycle_num, "X", 1);
      }
      cycle_line_num++;
    }
    fclose(pFile);
  }
  return cycle_num;
}


x86 assembly (clang, -O0):
<get_cycle_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0xe78(%rip),%ax
mov    %ax,-0x292(%rbp)
movl   $0xffffffff,-0x29c(%rbp)
ff ff ff
lea    0xe62(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     13e2 <get_cycle_number+0x282>
jmp    11c0 <get_cycle_number+0x60>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2a1(%rbp)
je     11f7 <get_cycle_number+0x97>
cmpl   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x2a1(%rbp)
mov    -0x2a1(%rbp),%al
test   $0x1,%al
jne    120a <get_cycle_number+0xaa>
jmp    13d9 <get_cycle_number+0x279>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     13ae <get_cycle_number+0x24e>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strstr@plt>
lea    -0x220(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x2b0(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2b0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x29c(%rbp)
movl   $0x1,-0x2a0(%rbp)
mov    -0x29c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%eax
ff
movsbl -0x292(%rbp),%ecx
cmp    %ecx,%eax
jne    129e <get_cycle_number+0x13e>
movl   $0x1,-0x2a0(%rbp)
jmp    1371 <get_cycle_number+0x211>
mov    -0x29c(%rbp),%eax
add    $0x2,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%eax
ff
movsbl -0x292(%rbp),%ecx
cmp    %ecx,%eax
jne    12cf <get_cycle_number+0x16f>
movl   $0x2,-0x2a0(%rbp)
jmp    136c <get_cycle_number+0x20c>
mov    -0x29c(%rbp),%eax
add    $0x3,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%eax
ff
movsbl -0x292(%rbp),%ecx
cmp    %ecx,%eax
jne    1300 <get_cycle_number+0x1a0>
movl   $0x3,-0x2a0(%rbp)
jmp    1367 <get_cycle_number+0x207>
mov    -0x29c(%rbp),%eax
add    $0x4,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%eax
ff
movsbl -0x292(%rbp),%ecx
cmp    %ecx,%eax
jne    1331 <get_cycle_number+0x1d1>
movl   $0x4,-0x2a0(%rbp)
jmp    1362 <get_cycle_number+0x202>
mov    -0x29c(%rbp),%eax
add    $0x5,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%eax
ff
movsbl -0x292(%rbp),%ecx
cmp    %ecx,%eax
jne    135d <get_cycle_number+0x1fd>
movl   $0x5,-0x2a0(%rbp)
jmp    1362 <get_cycle_number+0x202>
jmp    1367 <get_cycle_number+0x207>
jmp    136c <get_cycle_number+0x20c>
jmp    1371 <get_cycle_number+0x211>
mov    -0x10(%rbp),%rdi
movslq -0x29c(%rbp),%rax
lea    -0x220(%rbp),%rsi
add    %rax,%rsi
mov    -0x2a0(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x2a0(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13cb <get_cycle_number+0x26b>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rdi
lea    0xc5b(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c0 <get_cycle_number+0x60>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cycle_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe82(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1288 <get_cycle_number+0x128>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1280 <get_cycle_number+0x120>
mov    %rsp,%r15
lea    0xe61(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1207 <get_cycle_number+0xa7>
movb   $0x0,0x1(%rbx)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rbp,%rbp
jne    1280 <get_cycle_number+0x120>
test   %rax,%rax
jne    11c0 <get_cycle_number+0x60>
jmp    1280 <get_cycle_number+0x120>
sub    %r15d,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
cltq
mov    $0x1,%ebp
cmpb   $0x20,0x1(%rax,%r15,1)
je     125c <get_cycle_number+0xfc>
mov    $0x2,%ebp
cmpb   $0x20,0x2(%rax,%r15,1)
je     125c <get_cycle_number+0xfc>
mov    $0x3,%ebp
cmpb   $0x20,0x3(%rax,%r15,1)
je     125c <get_cycle_number+0xfc>
mov    $0x4,%ebp
cmpb   $0x20,0x4(%rax,%r15,1)
je     125c <get_cycle_number+0xfc>
xor    %ecx,%ecx
cmpb   $0x20,0x5(%rax,%r15,1)
sete   %cl
lea    0x1(,%rcx,4),%ebp
lea    (%rsp,%rax,1),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.get_cycle_number.space = [2 x i8] c" \00"
@.str = [24 x i8] c"/var/www/active_log.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"X\00"
define i8* @get_cycle_number(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca [100 x i8]
%10 = alloca [2 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 1, i32* %6
store i32 0, i32* %7
%14 = bitcast [2 x i8]* %10 to i8*
store i32 -1, i32* %12
%15 = 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* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %134
18: ; preds = %2
br label %19
19: ; preds = %128, %18
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i32* @fgets(i8* %20, i32 512, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br label %27
27: ; preds = %24, %19
%28 = phi i1 [ false, %19 ], [ %26, %24 ]
br i1 %28, label %29, label %131
29: ; preds = %27
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i8* @strstr(i8* %30, i8* %31)
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %123
34: ; preds = %29
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%36 = load i8*, i8** %3
%37 = call i8* @strstr(i8* %35, i8* %36)
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = load i8*, i8** %3
%43 = call i32 @strlen(i8* %42)
%44 = sext i32 %43 to i64
%45 = add nsw i64 %41, %44
%46 = trunc i64 %45 to i32
store i32 %46, i32* %12
store i32 1, i32* %13
%47 = load i32, i32* %12
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %52, %55
br i1 %56, label %57, label %58
57: ; preds = %34
store i32 1, i32* %13
br label %110
58: ; preds = %34
%59 = load i32, i32* %12
%60 = add nsw i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %64, %67
br i1 %68, label %69, label %70
69: ; preds = %58
store i32 2, i32* %13
br label %109
70: ; preds = %58
%71 = load i32, i32* %12
%72 = add nsw i32 %71, 3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp eq i32 %76, %79
br i1 %80, label %81, label %82
81: ; preds = %70
store i32 3, i32* %13
br label %108
82: ; preds = %70
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 4
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %88, %91
br i1 %92, label %93, label %94
93: ; preds = %82
store i32 4, i32* %13
br label %107
94: ; preds = %82
%95 = load i32, i32* %12
%96 = add nsw i32 %95, 5
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp eq i32 %100, %103
br i1 %104, label %105, label %106
105: ; preds = %94
store i32 5, i32* %13
br label %106
106: ; preds = %105, %94
br label %107
107: ; preds = %106, %93
br label %108
108: ; preds = %107, %81
br label %109
109: ; preds = %108, %69
br label %110
110: ; preds = %109, %57
%111 = load i8*, i8** %4
%112 = load i32, i32* %12
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %113
%115 = load i32, i32* %13
%116 = call i32 @strncpy(i8* %111, i8* %114, i32 %115)
%117 = load i8*, i8** %4
%118 = load i32, i32* %13
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* %117, i64 %119
store i8 0, i8* %120
%121 = load i32, i32* %7
%122 = add nsw i32 %121, 1
store i32 %122, i32* %7
br label %128
123: ; preds = %29
%124 = load i8*, i8** %4
%125 = getelementptr inbounds i8, i8* %124, i64 1
store i8 0, i8* %125
%126 = load i8*, i8** %4
%127 = call i32 @strncpy(i8* %126, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %128
128: ; preds = %123, %110
%129 = load i32, i32* %6
%130 = add nsw i32 %129, 1
store i32 %130, i32* %6
br label %19
131: ; preds = %27
%132 = load i32*, i32** %5
%133 = call i32 @fclose(i32* %132)
br label %134
134: ; preds = %131, %2
%135 = load i8*, i8** %4
ret i8* %135
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/www/active_log.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"X\00"
define i8* @get_cycle_number(i8* %0, i8* returned %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %67, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 512, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %65, label %10
10: ; preds = %7
%11 = ptrtoint [512 x i8]* %3 to i64
%12 = getelementptr inbounds i8, i8* %1, i64 1
br label %13
13: ; preds = %10, %60
%14 = call i8* @strstr(i8* %4, i8* dereferenceable(1) %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %60, label %16
16: ; preds = %13
%17 = ptrtoint i8* %14 to i64
%18 = sub i64 %17, %11
%19 = call i32 @strlen(i8* %0)
%20 = trunc i64 %18 to i32
%21 = add i32 %19, %20
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 32
br i1 %26, label %52, label %27
27: ; preds = %16
%28 = add nsw i32 %21, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 32
br i1 %32, label %52, label %33
33: ; preds = %27
%34 = add nsw i32 %21, 3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 32
br i1 %38, label %52, label %39
39: ; preds = %33
%40 = add nsw i32 %21, 4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 32
br i1 %44, label %52, label %45
45: ; preds = %39
%46 = add nsw i32 %21, 5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 32
%51 = select i1 %50, i32 5, i32 1
br label %52
52: ; preds = %16, %27, %33, %39, %45
%53 = phi i32 [ 1, %16 ], [ 2, %27 ], [ 3, %33 ], [ 4, %39 ], [ %51, %45 ]
%54 = sext i32 %21 to i64
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %54
%56 = call i32 @strncpy(i8* %1, i8* %55, i32 %53)
%57 = zext i32 %53 to i64
%58 = getelementptr inbounds i8, i8* %1, i64 %57
store i8 0, i8* %58
%59 = call i32* @fgets(i8* %4, i32 512, i32* %5)
br label %65
60: ; preds = %13
store i8 0, i8* %12
%61 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%62 = call i32* @fgets(i8* %4, i32 512, i32* %5)
%63 = icmp ne i32* %62, null
%64 = and i1 %15, %63
br i1 %64, label %13, label %65
65: ; preds = %60, %52, %7
%66 = call i32 @fclose(i32* %5)
br label %67
67: ; preds = %65, %2
ret i8* %1
}