#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 file_size(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int compare_to_file(const char *file, char *text, int *line, int *pos) {
  FILE *src = fopen(file, "r");
  if (src != NULL) {
    int len = file_size(src);
    int tlen = strlen(text);
    char *fcont = malloc(len);
    if (fcont != NULL) {
      int lineno = 1;
      int charno = 0;
      int n = fread(fcont, 1, len, src);
      if (n == len) {
        int i;
        for (i = 0; i < len && i < tlen; i++) {
          if (fcont[i] != text[i]) {
            *line = lineno;
            *pos = charno;
            free(fcont);
            return 0;
          } else if (fcont[i] == '\n') {
            lineno++;
            charno = 0;
          }
        }
        free(fcont);
        return 1;
      } else
        fprintf(stderr, "compare_to_file: failed to read %s\n", file);
      free(fcont);
    } else
      fprintf(stderr, "compare_to_file: failed allocation\n");
  } else
    fprintf(stderr, "compare_to_file: %s not available\n", file);
}


x86 assembly (clang, -O0):
<compare_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     131a <compare_to_file+0x1aa>
mov    -0x30(%rbp),%rdi
call   1060 <file_size@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12fe <compare_to_file+0x18e>
movl   $0x1,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    12d5 <compare_to_file+0x165>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%ecx
xor    %eax,%eax
cmp    -0x34(%rbp),%ecx
mov    %al,-0x51(%rbp)
jge    122c <compare_to_file+0xbc>
mov    -0x50(%rbp),%eax
cmp    -0x38(%rbp),%eax
setl   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    123c <compare_to_file+0xcc>
jmp    12c0 <compare_to_file+0x150>
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x50(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1283 <compare_to_file+0x113>
mov    -0x44(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1335 <compare_to_file+0x1c5>
mov    -0x40(%rbp),%rax
movslq -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12a8 <compare_to_file+0x138>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
jmp    12ad <compare_to_file+0x13d>
jmp    12b2 <compare_to_file+0x142>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    120f <compare_to_file+0x9f>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1335 <compare_to_file+0x1c5>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1315 <compare_to_file+0x1a5>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1335 <compare_to_file+0x1c5>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     124c <compare_to_file+0xdc>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %rax,%rdi
call   1060 <file_size@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1268 <compare_to_file+0xf8>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    %ebp,%eax
jne    1281 <compare_to_file+0x111>
test   %ebp,%ebp
jle    123d <compare_to_file+0xcd>
test   %r14d,%r14d
jle    123d <compare_to_file+0xcd>
mov    %r14d,%r8d
mov    %ebp,%ecx
mov    $0x1,%edx
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
movzbl -0x1(%rbx,%rsi,1),%eax
cmp    -0x1(%r12,%rsi,1),%al
jne    12b2 <compare_to_file+0x142>
xor    %edi,%edi
cmp    $0xa,%al
sete   %al
cmp    %rcx,%rsi
jae    123d <compare_to_file+0xcd>
mov    %al,%dil
add    %edi,%edx
lea    0x1(%rsi),%rax
cmp    %r8,%rsi
mov    %rax,%rsi
jb     1210 <compare_to_file+0xa0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    12a3 <compare_to_file+0x133>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a3 <compare_to_file+0x133>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a3 <compare_to_file+0x133>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rax
mov    %edx,(%rax)
mov    0x10(%rsp),%rax
movl   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12a3 <compare_to_file+0x133>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"compare_to_file: failed to read %s\0A\00"
@.str.2 = [36 x i8] c"compare_to_file: failed allocation\0A\00"
@.str.3 = [35 x i8] c"compare_to_file: %s not available\0A\00"
define i32 @compare_to_file(i8* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %101
22: ; preds = %4
%23 = load i32*, i32** %10
%24 = call i32 @file_size(i32* %23)
store i32 %24, i32* %11
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %12
%27 = load i32, i32* %11
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %13
%29 = load i8*, i8** %13
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %97
31: ; preds = %22
store i32 1, i32* %14
store i32 0, i32* %15
%32 = load i8*, i8** %13
%33 = load i32, i32* %11
%34 = load i32*, i32** %10
%35 = call i32 @fread(i8* %32, i32 1, i32 %33, i32* %34)
store i32 %35, i32* %16
%36 = load i32, i32* %16
%37 = load i32, i32* %11
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %90
39: ; preds = %31
store i32 0, i32* %17
br label %40
40: ; preds = %84, %39
%41 = load i32, i32* %17
%42 = load i32, i32* %11
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* %17
%46 = load i32, i32* %12
%47 = icmp slt i32 %45, %46
br label %48
48: ; preds = %44, %40
%49 = phi i1 [ false, %40 ], [ %47, %44 ]
br i1 %49, label %50, label %87
50: ; preds = %48
%51 = load i8*, i8** %13
%52 = load i32, i32* %17
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = load i8*, i8** %7
%58 = load i32, i32* %17
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %56, %62
br i1 %63, label %64, label %71
64: ; preds = %50
%65 = load i32, i32* %14
%66 = load i32*, i32** %8
store i32 %65, i32* %66
%67 = load i32, i32* %15
%68 = load i32*, i32** %9
store i32 %67, i32* %68
%69 = load i8*, i8** %13
%70 = call i32 @free(i8* %69)
store i32 0, i32* %5
br label %105
71: ; preds = %50
%72 = load i8*, i8** %13
%73 = load i32, i32* %17
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 10
br i1 %78, label %79, label %82
79: ; preds = %71
%80 = load i32, i32* %14
%81 = add nsw i32 %80, 1
store i32 %81, i32* %14
store i32 0, i32* %15
br label %82
82: ; preds = %79, %71
br label %83
83: ; preds = %82
br label %84
84: ; preds = %83
%85 = load i32, i32* %17
%86 = add nsw i32 %85, 1
store i32 %86, i32* %17
br label %40
87: ; preds = %48
%88 = load i8*, i8** %13
%89 = call i32 @free(i8* %88)
store i32 1, i32* %5
br label %105
90: ; preds = %31
%91 = load i32, i32* @stderr
%92 = load i8*, i8** %6
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %92)
br label %94
94: ; preds = %90
%95 = load i8*, i8** %13
%96 = call i32 @free(i8* %95)
br label %100
97: ; preds = %22
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %100
100: ; preds = %97, %94
br label %105
101: ; preds = %4
%102 = load i32, i32* @stderr
%103 = load i8*, i8** %6
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %103)
br label %105
105: ; preds = %64, %87, %101, %100
%106 = load i32, i32* %5
ret i32 %106
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"compare_to_file: failed to read %s\0A\00"
@.str.2 = [36 x i8] c"compare_to_file: failed allocation\0A\00"
@.str.3 = [35 x i8] c"compare_to_file: %s not available\0A\00"
define i32 @compare_to_file(i8* %0, i8* %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %49, label %7
7: ; preds = %4
%8 = tail call i32 @file_size(i32* %5)
%9 = tail call i32 @strlen(i8* %1)
%10 = tail call i8* @malloc(i32 %8)
%11 = icmp eq i8* %10, null
br i1 %11, label %46, label %12
12: ; preds = %7
%13 = tail call i32 @fread(i8* %10, i32 1, i32 %8, i32* %5)
%14 = icmp eq i32 %13, %8
br i1 %14, label %15, label %42
15: ; preds = %12
%16 = icmp sgt i32 %8, 0
%17 = icmp sgt i32 %9, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %40
19: ; preds = %15
%20 = zext i32 %9 to i64
%21 = zext i32 %8 to i64
br label %22
22: ; preds = %19, %32
%23 = phi i64 [ 0, %19 ], [ %36, %32 ]
%24 = phi i32 [ 1, %19 ], [ %35, %32 ]
%25 = getelementptr inbounds i8, i8* %10, i64 %23
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %1, i64 %23
%28 = load i8, i8* %27
%29 = icmp eq i8 %26, %28
br i1 %29, label %32, label %30
30: ; preds = %22
store i32 %24, i32* %2
store i32 0, i32* %3
%31 = tail call i32 @free(i8* %10)
br label %52
32: ; preds = %22
%33 = icmp eq i8 %26, 10
%34 = zext i1 %33 to i32
%35 = add nuw nsw i32 %24, %34
%36 = add nuw nsw i64 %23, 1
%37 = icmp ult i64 %36, %21
%38 = icmp ult i64 %36, %20
%39 = select i1 %37, i1 %38, i1 false
br i1 %39, label %22, label %40
40: ; preds = %32, %15
%41 = tail call i32 @free(i8* %10)
br label %52
42: ; preds = %12
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%45 = tail call i32 @free(i8* %10)
br label %52
46: ; preds = %7
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %52
49: ; preds = %4
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %52
52: ; preds = %42, %40, %30, %46, %49
%53 = phi i32 [ undef, %49 ], [ undef, %46 ], [ undef, %42 ], [ 0, %30 ], [ 1, %40 ]
ret i32 %53
}