#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, void *);
int strlen(char *);
scalar_t__ strstr(char *, char *);
char *strtok(char *, char *);
int ffscanf(char *fieldname, FILE *fp, char *format, void **inbuffer) {
  char buffer[100];
  int len;
  int commentflag = 0;
  char *pch;
  char *pch2;
  do {
    if (fgets(buffer, 99, fp) == 0) {
      return 0;
    }
    buffer[99] = '\0';
    len = strlen(buffer);
    if (buffer[len - 1] == '\n') {
      buffer[len - 1] = '\0';
    }
    switch (commentflag) {
    case 0:
      if (strstr(buffer, "/*") != 0) {
        commentflag = 1;
        if (strstr(buffer, "*/") != 0) {
          commentflag = 2;
        }
      }
      break;
    case 1:
      if (strstr(buffer, "*/") != 0) {
        commentflag = 2;
      }
      break;
    case 2:
      if (strstr(buffer, "/*") != 0) {
        commentflag = 1;
        if (strstr(buffer, "*/") != 0) {
          commentflag = 2;
        }
      } else {
        commentflag = 0;
      }
      break;
    }
  } while (commentflag != 0);
  if (strstr(buffer, fieldname) != 0) {
    pch = strtok(buffer, "=");
    pch2 = pch;
    while (pch != NULL) {
      pch2 = pch;
      pch = strtok(NULL, "= ");
    }
    sscanf(pch2, format, *inbuffer);
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<ffscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x63,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a0 <ffscanf+0x50>
movl   $0x0,-0x4(%rbp)
jmp    13c2 <ffscanf+0x272>
movb   $0x0,-0x2d(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11e5 <ffscanf+0x95>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
mov    %eax,-0xac(%rbp)
test   %eax,%eax
je     1226 <ffscanf+0xd6>
jmp    11fe <ffscanf+0xae>
mov    -0xac(%rbp),%eax
sub    $0x1,%eax
je     127e <ffscanf+0x12e>
jmp    1212 <ffscanf+0xc2>
mov    -0xac(%rbp),%eax
sub    $0x2,%eax
je     12aa <ffscanf+0x15a>
jmp    130c <ffscanf+0x1bc>
lea    -0x90(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1279 <ffscanf+0x129>
movl   $0x1,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1274 <ffscanf+0x124>
movl   $0x2,-0x98(%rbp)
jmp    1279 <ffscanf+0x129>
jmp    130c <ffscanf+0x1bc>
lea    -0x90(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     12a5 <ffscanf+0x155>
movl   $0x2,-0x98(%rbp)
jmp    130c <ffscanf+0x1bc>
lea    -0x90(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     12fd <ffscanf+0x1ad>
movl   $0x1,-0x98(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     12f8 <ffscanf+0x1a8>
movl   $0x2,-0x98(%rbp)
jmp    1307 <ffscanf+0x1b7>
movl   $0x0,-0x98(%rbp)
jmp    130c <ffscanf+0x1bc>
jmp    1311 <ffscanf+0x1c1>
cmpl   $0x0,-0x98(%rbp)
jne    1175 <ffscanf+0x25>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     13bb <ffscanf+0x26b>
lea    -0x90(%rbp),%rdi
lea    0xcc0(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     1398 <ffscanf+0x248>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc81(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa0(%rbp)
jmp    1360 <ffscanf+0x210>
mov    -0xa8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
call   1050 <sscanf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c2 <ffscanf+0x272>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffscanf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,%r12
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x63,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1274 <ffscanf+0x124>
mov    %r14,(%rsp)
mov    %rbp,0x8(%rsp)
xor    %r15d,%r15d
lea    0xe65(%rip),%rbp
lea    0xe61(%rip),%r14
jmp    11f2 <ffscanf+0xa2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1220 <ffscanf+0xd0>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
cmp    $0x1,%rax
mov    $0x2,%r15d
sbb    $0x0,%r15d
mov    %rbx,%rdi
mov    $0x63,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1274 <ffscanf+0x124>
movb   $0x0,0x73(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    120d <ffscanf+0xbd>
movb   $0x0,0xf(%rsp,%rax,1)
cmp    $0x2,%r15d
je     11b0 <ffscanf+0x60>
cmp    $0x1,%r15d
je     11c0 <ffscanf+0x70>
test   %r15d,%r15d
je     11b0 <ffscanf+0x60>
jmp    11d9 <ffscanf+0x89>
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1274 <ffscanf+0x124>
lea    0xdcd(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     1285 <ffscanf+0x135>
lea    0xdb9(%rip),%rbp
mov    0x8(%rsp),%r14
mov    (%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1260 <ffscanf+0x110>
jmp    1290 <ffscanf+0x140>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
mov    0x8(%rsp),%r14
mov    (%rsp),%r15
mov    (%r15),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <sscanf@plt>
mov    $0x1,%eax
jmp    1276 <ffscanf+0x126>

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

LLVM IR (-O2):
@.str = [3 x i8] c"/*\00"
@.str.1 = [3 x i8] c"*/\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [3 x i8] c"= \00"
define i32 @ffscanf(i8* %0, i32* nocapture %1, i8* nocapture %2, i8** nocapture %3) {
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = call i64 @fgets(i8* %6, i32 99, i32* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %49, label %9
9: ; preds = %4
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 99
br label %11
11: ; preds = %9, %31
%12 = phi i32 [ 0, %9 ], [ %32, %31 ]
store i8 0, i8* %10
%13 = call i32 @strlen(i8* %6)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %11
store i8 0, i8* %16
br label %20
20: ; preds = %19, %11
switch i32 %12, label %31 [
i32 0, label %21
i32 1, label %27
i32 2, label %24
]
21: ; preds = %20
%22 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %35, label %27
24: ; preds = %20
%25 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %24, %20, %21
%28 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i32 1, i32 2
br label %31
31: ; preds = %27, %20
%32 = phi i32 [ %12, %20 ], [ %30, %27 ]
%33 = call i64 @fgets(i8* %6, i32 99, i32* %1)
%34 = icmp eq i64 %33, 0
br i1 %34, label %49, label %11
35: ; preds = %21, %24
%36 = call i64 @strstr(i8* %6, i8* %0)
%37 = icmp eq i64 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %35
%39 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i8* %39, null
br i1 %40, label %45, label %41
41: ; preds = %38, %41
%42 = phi i8* [ %43, %41 ], [ %39, %38 ]
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %41
45: ; preds = %41, %38
%46 = phi i8* [ null, %38 ], [ %42, %41 ]
%47 = load i8*, i8** %3
%48 = call i32 @sscanf(i8* %46, i8* %2, i8* %47)
br label %49
49: ; preds = %31, %4, %35, %45
%50 = phi i32 [ 1, %45 ], [ 0, %35 ], [ 0, %4 ], [ 0, %31 ]
ret i32 %50
}