#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 size_t uint64_t;
struct stat {
  int st_size;
  int /*<<< orphan*/ st_mode;
};
struct file_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ error_func(char *, int, char *);
int /*<<< orphan*/ file_read_mmap(struct file_data *, int, size_t);
int /*<<< orphan*/ file_read_std(struct file_data *, int, size_t);
int fstat(int, struct stat *);
void file_read_fdes(struct file_data *fp, int fd) {
  struct stat st;
  int r;
  r = fstat(fd, &st);
  if (r)
    error_func("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/depp/libfresample/refs/heads/"
               "master/src/file.c",
               73, "stat failed");
  if (!S_ISREG(st.st_mode)) {
    file_read_std(fp, fd, 0);
    return;
  }
  if ((uint64_t)st.st_size > (size_t)-1)
    error_func("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/depp/libfresample/refs/heads/"
               "master/src/file.c",
               79, "file too large");
  if (st.st_size >= (8 * 1024)) {
    file_read_mmap(fp, fd, (size_t)st.st_size);
  } else {
    file_read_std(fp, fd, (size_t)st.st_size);
  }
}


x86 assembly (clang, -O0):
<file_read_fdes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1070 <fstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1190 <file_read_fdes+0x40>
lea    0xe81(%rip),%rdi
mov    $0x49,%esi
lea    0xefe(%rip),%rdx
call   1050 <error_func@plt>
mov    -0x14(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11b6 <file_read_fdes+0x66>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <file_read_std@plt>
jmp    120e <file_read_fdes+0xbe>
movslq -0x18(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
jbe    11dc <file_read_fdes+0x8c>
lea    0xe35(%rip),%rdi
mov    $0x4f,%esi
lea    0xebe(%rip),%rdx
call   1050 <error_func@plt>
cmpl   $0x2000,-0x18(%rbp)
jl     11fe <file_read_fdes+0xae>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movslq -0x18(%rbp),%rdx
call   1030 <file_read_mmap@plt>
jmp    120e <file_read_fdes+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movslq -0x18(%rbp),%rdx
call   1040 <file_read_std@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_fdes>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %ebx,%edi
call   1070 <fstat@plt>
test   %eax,%eax
je     117f <file_read_fdes+0x2f>
lea    0xe92(%rip),%rdi
lea    0xf14(%rip),%rdx
mov    $0x49,%esi
call   1050 <error_func@plt>
mov    0x4(%rsp),%edi
call   1060 <S_ISREG@plt>
test   %eax,%eax
je     11a8 <file_read_fdes+0x58>
mov    (%rsp),%edx
cmp    $0x2000,%edx
jl     11b1 <file_read_fdes+0x61>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <file_read_mmap@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
jmp    11b9 <file_read_fdes+0x69>
movslq %edx,%rdx
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <file_read_std@plt>

LLVM IR (-O0):
%struct.file_data = type { i32 }
%struct.stat = type { i32, i32 }
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/depp/libfresample/refs/heads/master/src/file.c\00"
@.str.1 = [12 x i8] c"stat failed\00"
@.str.2 = [15 x i8] c"file too large\00"
define void @file_read_fdes(%struct.file_data* %0, i32 %1) {
%3 = alloca %struct.file_data*
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i32
store %struct.file_data* %0, %struct.file_data** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @fstat(i32 %7, %struct.stat* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @error_func(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @S_ISREG(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load %struct.file_data*, %struct.file_data** %3
%20 = load i32, i32* %4
%21 = call i32 @file_read_std(%struct.file_data* %19, i32 %20, i64 0)
br label %47
22: ; preds = %13
%23 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = icmp ugt i64 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @error_func(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 79, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = icmp sge i32 %31, 8192
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load %struct.file_data*, %struct.file_data** %3
%35 = load i32, i32* %4
%36 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = call i32 @file_read_mmap(%struct.file_data* %34, i32 %35, i64 %38)
br label %47
40: ; preds = %29
%41 = load %struct.file_data*, %struct.file_data** %3
%42 = load i32, i32* %4
%43 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = call i32 @file_read_std(%struct.file_data* %41, i32 %42, i64 %45)
br label %47
47: ; preds = %18, %40, %33
ret void
}

LLVM IR (-O2):
%struct.file_data = type { i32 }
%struct.stat = type { i32, i32 }
@.str = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/depp/libfresample/refs/heads/master/src/file.c\00"
@.str.1 = [12 x i8] c"stat failed\00"
define void @file_read_fdes(%struct.file_data* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @fstat(i32 %1, %struct.stat* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @error_func(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str, i64 0, i64 0), i32 73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = tail call i32 @S_ISREG(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @file_read_std(%struct.file_data* %0, i32 %1, i64 0)
br label %26
16: ; preds = %9
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 8191
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = zext i32 %18 to i64
%22 = tail call i32 @file_read_mmap(%struct.file_data* %0, i32 %1, i64 %21)
br label %26
23: ; preds = %16
%24 = sext i32 %18 to i64
%25 = tail call i32 @file_read_std(%struct.file_data* %0, i32 %1, i64 %24)
br label %26
26: ; preds = %20, %23, %14
ret void
}