#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
size_t feof(int /*<<< orphan*/ *);
size_t ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long long, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ logger(char *, ...);
char *malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int strncmp(char const *, char *, size_t);
int compare_string_and_ulysses(const char *s, const char *path) {
  FILE *fd = fopen(path, "rb");
  if (!fd) {
    logger("Can't open Ulysses for reading\n");
    return -1;
  }
  fseek(fd, 0ll, SEEK_END);
  size_t size = ftell(fd);
  rewind(fd);
  char *buf = malloc(sizeof(char) * size);
  if (!buf) {
    logger("Can't allocate memory\n");
    return -1;
  }
  size_t res = fread(buf, sizeof(char), size, fd);
  if (res != size) {
    logger("Bytes readed: %llu\n", res);
    logger("Is EOF: %d\n", feof(fd));
    logger("Is error: %d\n", ferror(fd));
    return -1;
  }
  int cmp = strncmp(s, buf, size);
  fclose(fd);
  if (cmp == 0) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<compare_string_and_ulysses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f9 <compare_string_and_ulysses+0x49>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   10a0 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <compare_string_and_ulysses+0x161>
mov    -0x20(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125d <compare_string_and_ulysses+0xad>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   10a0 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <compare_string_and_ulysses+0x161>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     12d7 <compare_string_and_ulysses+0x127>
mov    -0x38(%rbp),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   10a0 <logger@plt>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
mov    %rax,%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   10a0 <logger@plt>
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
mov    %rax,%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   10a0 <logger@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1311 <compare_string_and_ulysses+0x161>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    130a <compare_string_and_ulysses+0x15a>
movl   $0x1,-0x4(%rbp)
jmp    1311 <compare_string_and_ulysses+0x161>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_string_and_ulysses>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe3b(%rip),%rsi
mov    %rax,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1244 <compare_string_and_ulysses+0x94>
mov    %rax,%rbx
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r15d,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     124d <compare_string_and_ulysses+0x9d>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    %r15,%rax
jne    125d <compare_string_and_ulysses+0xad>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
jmp    12a5 <compare_string_and_ulysses+0xf5>
lea    0xdb8(%rip),%rdi
jmp    1254 <compare_string_and_ulysses+0xa4>
lea    0xdcf(%rip),%rdi
xor    %eax,%eax
call   10a0 <logger@plt>
jmp    12a0 <compare_string_and_ulysses+0xf0>
lea    0xdd6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <logger@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
lea    0xdd1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <logger@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
lea    0xdc4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <logger@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Can't open Ulysses for reading\0A\00"
@SEEK_END = global i32 0
@.str.2 = [23 x i8] c"Can't allocate memory\0A\00"
@.str.3 = [20 x i8] c"Bytes readed: %llu\0A\00"
@.str.4 = [12 x i8] c"Is EOF: %d\0A\00"
@.str.5 = [14 x i8] c"Is error: %d\0A\00"
define i32 @compare_string_and_ulysses(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i64 0, i32 %19)
%21 = load i32*, i32** %6
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %7
%23 = load i32*, i32** %6
%24 = call i32 @rewind(i32* %23)
%25 = load i64, i64* %7
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %17
%32 = call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %61
33: ; preds = %17
%34 = load i8*, i8** %8
%35 = load i64, i64* %7
%36 = load i32*, i32** %6
%37 = call i64 @fread(i8* %34, i32 1, i64 %35, i32* %36)
store i64 %37, i64* %9
%38 = load i64, i64* %9
%39 = load i64, i64* %7
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %33
%42 = load i64, i64* %9
%43 = call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %42)
%44 = load i32*, i32** %6
%45 = call i64 @feof(i32* %44)
%46 = call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 %45)
%47 = load i32*, i32** %6
%48 = call i64 @ferror(i32* %47)
%49 = call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %48)
store i32 -1, i32* %3
br label %61
50: ; preds = %33
%51 = load i8*, i8** %4
%52 = load i8*, i8** %8
%53 = load i64, i64* %7
%54 = call i32 @strncmp(i8* %51, i8* %52, i64 %53)
store i32 %54, i32* %10
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* %10
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %50
store i32 1, i32* %3
br label %61
60: ; preds = %50
store i32 0, i32* %3
br label %61
61: ; preds = %60, %59, %41, %31, %15
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Can't open Ulysses for reading\0A\00"
@SEEK_END = global i32 0
@.str.2 = [23 x i8] c"Can't allocate memory\0A\00"
@.str.3 = [20 x i8] c"Bytes readed: %llu\0A\00"
@.str.4 = [12 x i8] c"Is EOF: %d\0A\00"
@.str.5 = [14 x i8] c"Is error: %d\0A\00"
define i32 @compare_string_and_ulysses(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %31
7: ; preds = %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %3, i64 0, i32 %8)
%10 = tail call i64 @ftell(i32* %3)
%11 = tail call i32 @rewind(i32* %3)
%12 = trunc i64 %10 to i32
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %31
17: ; preds = %7
%18 = tail call i64 @fread(i8* %13, i32 1, i64 %10, i32* %3)
%19 = icmp eq i64 %18, %10
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %18)
%22 = tail call i64 @feof(i32* %3)
%23 = tail call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 %22)
%24 = tail call i64 @ferror(i32* %3)
%25 = tail call i32 (i8*, ...) @logger(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %24)
br label %31
26: ; preds = %17
%27 = tail call i32 @strncmp(i8* %0, i8* %13, i64 %10)
%28 = tail call i32 @fclose(i32* %3)
%29 = icmp eq i32 %27, 0
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %15, %26, %20, %5
%32 = phi i32 [ -1, %5 ], [ -1, %15 ], [ -1, %20 ], [ %30, %26 ]
ret i32 %32
}