#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*/ LOG_NOTICE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ remove_newline_ch(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
int token_search(char *filename, int num_token, char *tokens[], int num_match,
                 char *matches[]) {
  int i;
  int line_count = 0;
  FILE *fp;
  char *token;
  char *match;
  char str[80];
  const char s[2] = "=";
  fp = fopen(filename, "r");
  if (fp == NULL) {
    perror("Error opening file");
    return (-1);
  }
  while (fgets(str, 60, fp) != NULL) {
    token = strtok(str, s);
    match = strtok(NULL, s);
    if (token == NULL) {
      syslog(LOG_NOTICE, "Invalid line..%s\n", token);
      continue;
    }
    for (i = 0; i < num_token; i++) {
      if (strcmp(token, tokens[i]) == 0) {
        matches[i] = malloc(strlen(match) * sizeof(char));
        strcpy(matches[i], match);
        remove_newline_ch(matches[i]);
      }
    }
  }
  if (feof(fp)) {
    fclose(fp);
  }
  return (1);
}


x86 assembly (clang, -O0):
<token_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0xe15(%rip),%ax
mov    %ax,-0xa2(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1229 <token_search+0x69>
lea    0xdec(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1359 <token_search+0x199>
jmp    122e <token_search+0x6e>
lea    -0xa0(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x3c,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1336 <token_search+0x176>
lea    -0xa0(%rbp),%rdi
lea    -0xa2(%rbp),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x48(%rbp)
lea    -0xa2(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <strtok@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12a1 <token_search+0xe1>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xd80(%rip),%rsi
call   10b0 <syslog@plt>
jmp    122e <token_search+0x6e>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1331 <token_search+0x171>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    131e <token_search+0x15e>
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x50(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <remove_newline_ch@plt>
jmp    1323 <token_search+0x163>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12a8 <token_search+0xe8>
jmp    122e <token_search+0x6e>
mov    -0x40(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1352 <token_search+0x192>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<token_search>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8,%r15
mov    %rdx,%rbx
mov    %esi,0x4(%rsp)
movw   $0x3d,0x2(%rsp)
lea    0xe1a(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     130e <token_search+0x14e>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x3c,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12e3 <token_search+0x123>
mov    0x4(%rsp),%r13d
lea    0x10(%rsp),%rbp
mov    %r14,0x8(%rsp)
jmp    1266 <token_search+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %edx,%edx
call   10b0 <syslog@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3c,%esi
mov    0x8(%rsp),%r14
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12e3 <token_search+0x123>
mov    %rbp,%rdi
lea    0x2(%rsp),%rbp
mov    %rbp,%rsi
call   10e0 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
call   10e0 <strtok@plt>
test   %r12,%r12
je     1230 <token_search+0x70>
cmpl   $0x0,0x4(%rsp)
jle    1247 <token_search+0x87>
mov    %rax,%r14
xor    %ebp,%ebp
jmp    12a9 <token_search+0xe9>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1247 <token_search+0x87>
mov    (%rbx,%rbp,8),%rsi
mov    %r12,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12a0 <token_search+0xe0>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r15,%rbp,8)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%r15,%rbp,8),%rdi
call   1070 <remove_newline_ch@plt>
jmp    12a0 <token_search+0xe0>
mov    %r14,%rdi
call   1090 <feof@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     12fd <token_search+0x13d>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xced(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    12fd <token_search+0x13d>

LLVM IR (-O0):
@__const.token_search.s = [2 x i8] c"=\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"Error opening file\00"
@LOG_NOTICE = global i32 0
@.str.2 = [18 x i8] c"Invalid line..%s\0A\00"
define i32 @token_search(i8* %0, i32 %1, i8** %2, i32 %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca [80 x i8]
%18 = alloca [2 x i8]
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8** %2, i8*** %9
store i32 %3, i32* %10
store i8** %4, i8*** %11
store i32 0, i32* %13
%19 = bitcast [2 x i8]* %18 to i8*
%20 = load i8*, i8** %7
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %14
%22 = load i32*, i32** %14
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %5
%25 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %95
26: ; preds = %5
br label %27
27: ; preds = %86, %40, %26
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %17, i64 0, i64 0
%29 = load i32*, i32** %14
%30 = call i32* @fgets(i8* %28, i32 60, i32* %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %87
32: ; preds = %27
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %17, i64 0, i64 0
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %18, i64 0, i64 0
%35 = call i8* @strtok(i8* %33, i8* %34)
store i8* %35, i8** %15
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %18, i64 0, i64 0
%37 = call i8* @strtok(i8* null, i8* %36)
store i8* %37, i8** %16
%38 = load i8*, i8** %15
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %44
40: ; preds = %32
%41 = load i32, i32* @LOG_NOTICE
%42 = load i8*, i8** %15
%43 = call i32 @syslog(i32 %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %27
44: ; preds = %32
store i32 0, i32* %12
br label %45
45: ; preds = %83, %44
%46 = load i32, i32* %12
%47 = load i32, i32* %8
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %86
49: ; preds = %45
%50 = load i8*, i8** %15
%51 = load i8**, i8*** %9
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i64 @strcmp(i8* %50, i8* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %82
58: ; preds = %49
%59 = load i8*, i8** %16
%60 = call i32 @strlen(i8* %59)
%61 = sext i32 %60 to i64
%62 = mul i64 %61, 1
%63 = trunc i64 %62 to i32
%64 = call i8* @malloc(i32 %63)
%65 = load i8**, i8*** %11
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
store i8* %64, i8** %68
%69 = load i8**, i8*** %11
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
%73 = load i8*, i8** %72
%74 = load i8*, i8** %16
%75 = call i32 @strcpy(i8* %73, i8* %74)
%76 = load i8**, i8*** %11
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
%81 = call i32 @remove_newline_ch(i8* %80)
br label %82
82: ; preds = %58, %49
br label %83
83: ; preds = %82
%84 = load i32, i32* %12
%85 = add nsw i32 %84, 1
store i32 %85, i32* %12
br label %45
86: ; preds = %45
br label %27
87: ; preds = %27
%88 = load i32*, i32** %14
%89 = call i64 @feof(i32* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = load i32*, i32** %14
%93 = call i32 @fclose(i32* %92)
br label %94
94: ; preds = %91, %87
store i32 1, i32* %6
br label %95
95: ; preds = %94, %24
%96 = load i32, i32* %6
ret i32 %96
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [19 x i8] c"Error opening file\00"
@LOG_NOTICE = global i32 0
@.str.2 = [18 x i8] c"Invalid line..%s\0A\00"
define i32 @token_search(i8* nocapture %0, i32 %1, i8** nocapture %2, i32 %3, i8** nocapture %4) {
%6 = alloca [80 x i8]
%7 = alloca i16
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%9 = bitcast i16* %7 to i8*
store i16 61, i16* %7
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %18, label %12
12: ; preds = %5
%13 = call i32* @fgets(i8* %8, i32 60, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %47, label %15
15: ; preds = %12
%16 = icmp sgt i32 %1, 0
%17 = zext i32 %1 to i64
br label %20
18: ; preds = %5
%19 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %52
20: ; preds = %15, %28
%21 = call i8* @strtok(i8* %8, i8* %9)
%22 = call i8* @strtok(i8* null, i8* %9)
%23 = icmp eq i8* %21, null
br i1 %23, label %25, label %24
24: ; preds = %20
br i1 %16, label %31, label %28
25: ; preds = %20
%26 = load i32, i32* @LOG_NOTICE
%27 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %28
28: ; preds = %44, %24, %25
%29 = call i32* @fgets(i8* %8, i32 60, i32* %10)
%30 = icmp eq i32* %29, null
br i1 %30, label %47, label %20
31: ; preds = %24, %44
%32 = phi i64 [ %45, %44 ], [ 0, %24 ]
%33 = getelementptr inbounds i8*, i8** %2, i64 %32
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %21, i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = call i32 @strlen(i8* %22)
%39 = call i8* @malloc(i32 %38)
%40 = getelementptr inbounds i8*, i8** %4, i64 %32
store i8* %39, i8** %40
%41 = call i32 @strcpy(i8* %39, i8* %22)
%42 = load i8*, i8** %40
%43 = call i32 @remove_newline_ch(i8* %42)
br label %44
44: ; preds = %31, %37
%45 = add nuw nsw i64 %32, 1
%46 = icmp eq i64 %45, %17
br i1 %46, label %28, label %31
47: ; preds = %28, %12
%48 = call i64 @feof(i32* %10)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = call i32 @fclose(i32* %10)
br label %52
52: ; preds = %47, %50, %18
%53 = phi i32 [ -1, %18 ], [ 1, %50 ], [ 1, %47 ]
ret i32 %53
}