#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 */
struct input {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
char *input_line(struct input *);
int /*<<< orphan*/ input_next(struct input *);
int /*<<< orphan*/ nthtoken(char *, char *, char *, int);
scalar_t__ startswith(char *, char *);
scalar_t__ strcmp(char *, char *);
int match_files(struct input *input, FILE *realfile) {
  char separator[128];
  char line[1024];
  char *expected = input_line(input);
  nthtoken(separator, expected, " \n", 1);
  input_next(input);
  while ((expected = input_line(input))) {
    if (startswith(expected, separator))
      break;
    if (!fgets(line, 1024, realfile))
      return 1;
    if (strcmp(expected, line))
      return 1;
    input_next(input);
  }
  if (fgets(line, 1024, realfile))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<match_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <input_line@plt>
mov    %rax,-0x4a8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x4a8(%rbp),%rsi
lea    0xe68(%rip),%rdx
mov    $0x1,%ecx
call   1030 <nthtoken@plt>
mov    -0x10(%rbp),%rdi
call   1040 <input_next@plt>
mov    -0x10(%rbp),%rdi
call   1080 <input_line@plt>
mov    %rax,-0x4a8(%rbp)
cmp    $0x0,%rax
je     1249 <match_files+0xe9>
mov    -0x4a8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1070 <startswith@plt>
cmp    $0x0,%rax
je     11e7 <match_files+0x87>
jmp    1249 <match_files+0xe9>
lea    -0x4a0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1212 <match_files+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    127b <match_files+0x11b>
mov    -0x4a8(%rbp),%rdi
lea    -0x4a0(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     123b <match_files+0xdb>
movl   $0x1,-0x4(%rbp)
jmp    127b <match_files+0x11b>
mov    -0x10(%rbp),%rdi
call   1040 <input_next@plt>
jmp    11ab <match_files+0x4b>
lea    -0x4a0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1274 <match_files+0x114>
movl   $0x1,-0x4(%rbp)
jmp    127b <match_files+0x11b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x488,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
call   1080 <input_line@plt>
lea    0xe7d(%rip),%rdx
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x1,%ecx
call   1030 <nthtoken@plt>
mov    %r13,%rdi
call   1040 <input_next@plt>
mov    %r13,%rdi
call   1080 <input_line@plt>
test   %rax,%rax
je     120d <match_files+0xad>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0x80(%rsp),%r12
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <startswith@plt>
test   %rax,%rax
jne    120d <match_files+0xad>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122b <match_files+0xcb>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    122b <match_files+0xcb>
mov    %r13,%rdi
call   1040 <input_next@plt>
mov    %r13,%rdi
call   1080 <input_line@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <match_files+0x60>
lea    0x80(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x488,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input = type { i32 }
@.str = [3 x i8] c" \0A\00"
define i32 @match_files(%struct.input* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.input*
%5 = alloca i32*
%6 = alloca [128 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
store %struct.input* %0, %struct.input** %4
store i32* %1, i32** %5
%9 = load %struct.input*, %struct.input** %4
%10 = call i8* @input_line(%struct.input* %9)
store i8* %10, i8** %8
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %8
%13 = call i32 @nthtoken(i8* %11, i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = load %struct.input*, %struct.input** %4
%15 = call i32 @input_next(%struct.input* %14)
br label %16
16: ; preds = %38, %2
%17 = load %struct.input*, %struct.input** %4
%18 = call i8* @input_line(%struct.input* %17)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = call i64 @startswith(i8* %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %41
26: ; preds = %20
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %5
%29 = call i64 @fgets(i8* %27, i32 1024, i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %26
store i32 1, i32* %3
br label %48
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %3
br label %48
38: ; preds = %32
%39 = load %struct.input*, %struct.input** %4
%40 = call i32 @input_next(%struct.input* %39)
br label %16
41: ; preds = %25, %16
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = load i32*, i32** %5
%44 = call i64 @fgets(i8* %42, i32 1024, i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
store i32 1, i32* %3
br label %48
47: ; preds = %41
store i32 0, i32* %3
br label %48
48: ; preds = %47, %46, %37, %31
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.input = type { i32 }
@.str = [3 x i8] c" \0A\00"
define i32 @match_files(%struct.input* %0, i32* nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @input_line(%struct.input* %0)
%8 = call i32 @nthtoken(i8* %5, i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 1)
%9 = call i32 @input_next(%struct.input* %0)
%10 = call i8* @input_line(%struct.input* %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %26, label %12
12: ; preds = %2, %22
%13 = phi i8* [ %24, %22 ], [ %10, %2 ]
%14 = call i64 @startswith(i8* %13, i8* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = call i64 @fgets(i8* %6, i32 1024, i32* %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %16
%20 = call i64 @strcmp(i8* %13, i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = call i32 @input_next(%struct.input* %0)
%24 = call i8* @input_line(%struct.input* %0)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %12
26: ; preds = %22, %12, %2
%27 = call i64 @fgets(i8* %6, i32 1024, i32* %1)
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %19, %16, %26
%31 = phi i32 [ %29, %26 ], [ 1, %16 ], [ 1, %19 ]
ret i32 %31
}