#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *input_line(struct input *);
int match_files(struct input *, int /*<<< orphan*/ *);
int /*<<< orphan*/ nthtoken(char *, char *, char *, int);
int read_file(struct input *input) {
  char filename[1024];
  FILE *realinput;
  char *line = input_line(input);
  int result;
  nthtoken(filename, line, " \n", 3);
  if (!(realinput = fopen(filename, "r")))
    return 1;
  result = match_files(input, realinput);
  fclose(realinput);
  return result;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <input_line@plt>
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rsi
lea    0xe7c(%rip),%rdx
mov    $0x3,%ecx
call   1030 <nthtoken@plt>
lea    -0x410(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
jne    11be <read_file+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    11e9 <read_file+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   1050 <match_files@plt>
mov    %eax,-0x424(%rbp)
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
call   1060 <input_line@plt>
lea    0xe96(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x3,%ecx
call   1030 <nthtoken@plt>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ab <read_file+0x5b>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <match_files@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11b0 <read_file+0x60>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.input = type { i32 }
@.str = [3 x i8] c" \0A\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @read_file(%struct.input* %0) {
%2 = alloca i32
%3 = alloca %struct.input*
%4 = alloca [1024 x i8]
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store %struct.input* %0, %struct.input** %3
%8 = load %struct.input*, %struct.input** %3
%9 = call i8* @input_line(%struct.input* %8)
store i8* %9, i8** %6
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = call i32 @nthtoken(i8* %10, i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
store i32 1, i32* %2
br label %24
17: ; preds = %1
%18 = load %struct.input*, %struct.input** %3
%19 = load i32*, i32** %5
%20 = call i32 @match_files(%struct.input* %18, i32* %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %5
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %2
br label %24
24: ; preds = %17, %16
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.input = type { i32 }
@.str = [3 x i8] c" \0A\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @read_file(%struct.input* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @input_line(%struct.input* %0)
%5 = call i32 @nthtoken(i8* %3, i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = call i32 @match_files(%struct.input* %0, i32* %6)
%10 = call i32 @fclose(i32* %6)
br label %11
11: ; preds = %1, %8
%12 = phi i32 [ %9, %8 ], [ 1, %1 ]
ret i32 %12
}