#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int GetCgiBase(char *CGI_FILE, char *keyword, char *str) {
  FILE *fp;
  char line[300];
  char key[40];
  int retVal = 0;
  if ((fp = fopen(CGI_FILE, "rt")) == NULL) {
    printf("file [%s] open error!!<br>\r", CGI_FILE);
    return retVal;
  }
  while (fgets(line, 300, fp)) {
    if (strlen(line) < 10)
      continue;
    if (line[0] == '/')
      continue;
    if (sscanf(line, "%s = %s", key, str) != 2) {
      continue;
    }
    if (strcmp(key, keyword) == 0) {
      retVal = 1;
      break;
    }
  }
  fclose(fp);
  return retVal;
}


x86 assembly (clang, -O0):
<GetCgiBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x194(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11cd <GetCgiBase+0x5d>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    -0x194(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128c <GetCgiBase+0x11c>
jmp    11d2 <GetCgiBase+0x62>
lea    -0x160(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x12c,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     127a <GetCgiBase+0x10a>
lea    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
jge    120b <GetCgiBase+0x9b>
jmp    11d2 <GetCgiBase+0x62>
movsbl -0x160(%rbp),%eax
cmp    $0x2f,%eax
jne    1220 <GetCgiBase+0xb0>
jmp    11d2 <GetCgiBase+0x62>
lea    -0x160(%rbp),%rdi
lea    -0x190(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xde6(%rip),%rsi
call   1080 <sscanf@plt>
cmp    $0x2,%eax
je     124c <GetCgiBase+0xdc>
jmp    11d2 <GetCgiBase+0x62>
lea    -0x190(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1275 <GetCgiBase+0x105>
movl   $0x1,-0x194(%rbp)
jmp    127a <GetCgiBase+0x10a>
jmp    11d2 <GetCgiBase+0x62>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x194(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetCgiBase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1226 <GetCgiBase+0xb6>
mov    %rax,%rbx
lea    0x30(%rsp),%rdi
mov    $0x12c,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     123b <GetCgiBase+0xcb>
lea    0x30(%rsp),%rbp
lea    0xe54(%rip),%r13
mov    %rsp,%r12
jmp    11e5 <GetCgiBase+0x75>
mov    %rbp,%rdi
mov    $0x12c,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1239 <GetCgiBase+0xc9>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
jl     11d0 <GetCgiBase+0x60>
cmpb   $0x2f,0x30(%rsp)
je     11d0 <GetCgiBase+0x60>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1080 <sscanf@plt>
cmp    $0x2,%eax
jne    11d0 <GetCgiBase+0x60>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11d0 <GetCgiBase+0x60>
mov    $0x1,%ebp
jmp    123b <GetCgiBase+0xcb>
lea    0xdd6(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    1243 <GetCgiBase+0xd3>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x168,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [28 x i8] c"file [%s] open error!!<br>\0D\00"
@.str.2 = [8 x i8] c"%s = %s\00"
define i32 @GetCgiBase(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [300 x i8]
%10 = alloca [40 x i8]
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %11
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %11
store i32 %18, i32* %4
br label %54
19: ; preds = %3
br label %20
20: ; preds = %49, %42, %35, %29, %19
%21 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%22 = load i32*, i32** %8
%23 = call i64 @fgets(i8* %21, i32 300, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %20
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %27, 10
br i1 %28, label %29, label %30
29: ; preds = %25
br label %20
30: ; preds = %25
%31 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br i1 %34, label %35, label %36
35: ; preds = %30
br label %20
36: ; preds = %30
%37 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%39 = load i8*, i8** %7
%40 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
%41 = icmp ne i32 %40, 2
br i1 %41, label %42, label %43
42: ; preds = %36
br label %20
43: ; preds = %36
%44 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%45 = load i8*, i8** %6
%46 = call i64 @strcmp(i8* %44, i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 1, i32* %11
br label %50
49: ; preds = %43
br label %20
50: ; preds = %48, %20
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
%53 = load i32, i32* %11
store i32 %53, i32* %4
br label %54
54: ; preds = %50, %15
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [28 x i8] c"file [%s] open error!!<br>\0D\00"
@.str.2 = [8 x i8] c"%s = %s\00"
define i32 @GetCgiBase(i8* %0, i8* %1, i8* %2) {
%4 = alloca [300 x i8]
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = call i64 @fgets(i8* %6, i32 300, i32* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %30, label %15
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
15: ; preds = %10, %21
%16 = call i32 @strlen(i8* %6)
%17 = icmp slt i32 %16, 10
%18 = load i8, i8* %6
%19 = icmp eq i8 %18, 47
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %24
21: ; preds = %15, %24, %27
%22 = call i64 @fgets(i8* %6, i32 300, i32* %8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %15
24: ; preds = %15
%25 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %2)
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %21
27: ; preds = %24
%28 = call i64 @strcmp(i8* %7, i8* %1)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %21
30: ; preds = %21, %27, %10
%31 = phi i32 [ 0, %10 ], [ 1, %27 ], [ 0, %21 ]
%32 = call i32 @fclose(i32* %8)
br label %33
33: ; preds = %30, %13
%34 = phi i32 [ 0, %13 ], [ %31, %30 ]
ret i32 %34
}