#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*/ LOGGER_log(char *, char *, int, ...);
int /*<<< orphan*/ clearerr(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stdin;
int MIME_read(char *mpname) {
  long int fsize = -1;
  char *buffer;
  size_t readcount, writecount;
  FILE *fout;
  buffer = malloc((8 * 1024) * sizeof(char));
  if (!buffer) {
    LOGGER_log(
        "%s:%d:MIME_read:ERROR: could not allocate 4K of memory for file read "
        "buffer\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/inflex/ripMIME/refs/heads/master/mime.c",
        2254);
    return -1;
  }
  fout = fopen(mpname, "w");
  if (!fout) {
    LOGGER_log(
        "%s:%d:MIME_read:ERROR: Cannot open file %s for writing... check "
        "permissions perhaps?",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/inflex/ripMIME/refs/heads/master/mime.c",
        2266, mpname);
    return -1;
  }
  if (fout) {
    fsize = 0;
    while (!feof(stdin)) {
      readcount = fread(buffer, 1, (((8 * 1024) - 1) * sizeof(char)), stdin);
      if (readcount > 0) {
        writecount = fwrite(buffer, 1, readcount, fout);
        fsize += writecount;
        if (readcount != writecount) {
          LOGGER_log("%s:%d:MIME_read:ERROR: Attempted to write %d bytes, but "
                     "only managed %d to file '%s'",
                     "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/inflex/ripMIME/refs/"
                     "heads/master/mime.c",
                     2288, readcount, writecount, mpname);
        }
      } else {
        break;
      }
    }
    fflush(fout);
    fclose(fout);
    if (feof(stdin))
      clearerr(stdin);
  }
  if (buffer)
    free(buffer);
  return (int)(fsize / 1024);
}


x86 assembly (clang, -O0):
<MIME_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
mov    $0x2000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <MIME_read+0x53>
lea    0xe2c(%rip),%rdi
lea    0xe72(%rip),%rsi
mov    $0x8ce,%edx
mov    $0x0,%al
call   10c0 <LOGGER_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1369 <MIME_read+0x1c9>
mov    -0x10(%rbp),%rdi
lea    0xed1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123c <MIME_read+0x9c>
mov    -0x10(%rbp),%rcx
lea    0xeb4(%rip),%rdi
lea    0xe29(%rip),%rsi
mov    $0x8da,%edx
mov    $0x0,%al
call   10c0 <LOGGER_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1369 <MIME_read+0x1c9>
cmpq   $0x0,-0x38(%rbp)
je     1344 <MIME_read+0x1a4>
movq   $0x0,-0x18(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1273 <MIME_read+0xd3>
jmp    1307 <MIME_read+0x167>
mov    -0x20(%rbp),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x1fff,%edx
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    12fd <MIME_read+0x15d>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     12f8 <MIME_read+0x158>
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0xe41(%rip),%rdi
lea    0xd61(%rip),%rsi
mov    $0x8f0,%edx
mov    $0x0,%al
call   10c0 <LOGGER_log@plt>
jmp    1302 <MIME_read+0x162>
jmp    1307 <MIME_read+0x167>
jmp    124f <MIME_read+0xaf>
mov    -0x38(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     133f <MIME_read+0x19f>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   1070 <clearerr@plt>
jmp    1344 <MIME_read+0x1a4>
cmpq   $0x0,-0x20(%rbp)
je     1358 <MIME_read+0x1b8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MIME_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    $0x2000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1236 <MIME_read+0x96>
mov    %rax,%rbx
lea    0xf08(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1252 <MIME_read+0xb2>
mov    %rax,%r15
mov    0x2e0a(%rip),%r13
mov    0x0(%r13),%edi
call   1060 <feof@plt>
test   %rax,%rax
je     1283 <MIME_read+0xe3>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1090 <fflush@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x0(%r13),%edi
call   1060 <feof@plt>
test   %rax,%rax
je     121a <MIME_read+0x7a>
mov    0x0(%r13),%edi
call   1070 <clearerr@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x3ff(%r14),%rax
test   %r14,%r14
cmovns %r14,%rax
shr    $0xa,%rax
jmp    1274 <MIME_read+0xd4>
lea    0xdc3(%rip),%rdi
lea    0xe09(%rip),%rsi
mov    $0x8ce,%edx
xor    %eax,%eax
call   10c0 <LOGGER_log@plt>
jmp    126f <MIME_read+0xcf>
lea    0xe78(%rip),%rdi
lea    0xded(%rip),%rsi
mov    $0x8da,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <LOGGER_log@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,(%rsp)
xor    %r14d,%r14d
jmp    12a5 <MIME_read+0x105>
nopl   0x0(%rax)
add    %r12,%r14
mov    0x0(%r13),%edi
call   1060 <feof@plt>
test   %rax,%rax
jne    11f3 <MIME_read+0x53>
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1fff,%edx
call   1040 <fread@plt>
test   %rax,%rax
je     11f3 <MIME_read+0x53>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    %rax,%r12
cmp    %rax,%rbp
je     1290 <MIME_read+0xf0>
lea    0xe3d(%rip),%rdi
lea    0xd5d(%rip),%rsi
mov    $0x8f0,%edx
mov    %rbp,%rcx
mov    %r12,%r8
mov    (%rsp),%r9
xor    %eax,%eax
call   10c0 <LOGGER_log@plt>
jmp    1290 <MIME_read+0xf0>

LLVM IR (-O0):
@.str = [77 x i8] c"%s:%d:MIME_read:ERROR: could not allocate 4K of memory for file read buffer\0A\00"
@.str.1 = [130 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/inflex/ripMIME/refs/heads/master/mime.c\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [85 x i8] c"%s:%d:MIME_read:ERROR: Cannot open file %s for writing... check permissions perhaps?\00"
@stdin = global i32 0
@.str.4 = [85 x i8] c"%s:%d:MIME_read:ERROR: Attempted to write %d bytes, but only managed %d to file '%s'\00"
define i32 @MIME_read(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %3
store i64 -1, i64* %4
%9 = call i8* @malloc(i32 8192)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2254)
store i32 -1, i32* %2
br label %78
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2266, i8* %20)
store i32 -1, i32* %2
br label %78
22: ; preds = %14
%23 = load i32*, i32** %8
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %68
25: ; preds = %22
store i64 0, i64* %4
br label %26
26: ; preds = %55, %25
%27 = load i32, i32* @stdin
%28 = call i64 @feof(i32 %27)
%29 = icmp ne i64 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %56
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = load i32, i32* @stdin
%34 = call i64 @fread(i8* %32, i32 1, i32 8191, i32 %33)
store i64 %34, i64* %6
%35 = load i64, i64* %6
%36 = icmp ugt i64 %35, 0
br i1 %36, label %37, label %54
37: ; preds = %31
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = load i32*, i32** %8
%41 = call i64 @fwrite(i8* %38, i32 1, i64 %39, i32* %40)
store i64 %41, i64* %7
%42 = load i64, i64* %7
%43 = load i64, i64* %4
%44 = add i64 %43, %42
store i64 %44, i64* %4
%45 = load i64, i64* %6
%46 = load i64, i64* %7
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %53
48: ; preds = %37
%49 = load i64, i64* %6
%50 = load i64, i64* %7
%51 = load i8*, i8** %3
%52 = call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2288, i64 %49, i64 %50, i8* %51)
br label %53
53: ; preds = %48, %37
br label %55
54: ; preds = %31
br label %56
55: ; preds = %53
br label %26
56: ; preds = %54, %26
%57 = load i32*, i32** %8
%58 = call i32 @fflush(i32* %57)
%59 = load i32*, i32** %8
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* @stdin
%62 = call i64 @feof(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %56
%65 = load i32, i32* @stdin
%66 = call i32 @clearerr(i32 %65)
br label %67
67: ; preds = %64, %56
br label %68
68: ; preds = %67, %22
%69 = load i8*, i8** %5
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i8*, i8** %5
%73 = call i32 @free(i8* %72)
br label %74
74: ; preds = %71, %68
%75 = load i64, i64* %4
%76 = sdiv i64 %75, 1024
%77 = trunc i64 %76 to i32
store i32 %77, i32* %2
br label %78
78: ; preds = %74, %19, %12
%79 = load i32, i32* %2
ret i32 %79
}

LLVM IR (-O2):
@.str = [77 x i8] c"%s:%d:MIME_read:ERROR: could not allocate 4K of memory for file read buffer\0A\00"
@.str.1 = [130 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/inflex/ripMIME/refs/heads/master/mime.c\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [85 x i8] c"%s:%d:MIME_read:ERROR: Cannot open file %s for writing... check permissions perhaps?\00"
@stdin = global i32 0
@.str.4 = [85 x i8] c"%s:%d:MIME_read:ERROR: Attempted to write %d bytes, but only managed %d to file '%s'\00"
define i32 @MIME_read(i8* %0) {
%2 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2254)
br label %44
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = load i32, i32* @stdin
%11 = tail call i64 @feof(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %30
13: ; preds = %6
%14 = tail call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2266, i8* %0)
br label %44
15: ; preds = %9, %26
%16 = phi i64 [ %22, %26 ], [ 0, %9 ]
%17 = load i32, i32* @stdin
%18 = tail call i64 @fread(i8* %2, i32 1, i32 8191, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = tail call i64 @fwrite(i8* %2, i32 1, i64 %18, i32* %7)
%22 = add i64 %21, %16
%23 = icmp eq i64 %18, %21
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, i8*, i32, ...) @LOGGER_log(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.1, i64 0, i64 0), i32 2288, i64 %18, i64 %21, i8* %0)
br label %26
26: ; preds = %20, %24
%27 = load i32, i32* @stdin
%28 = tail call i64 @feof(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %15, label %30
30: ; preds = %26, %15, %9
%31 = phi i64 [ 0, %9 ], [ %16, %15 ], [ %22, %26 ]
%32 = tail call i32 @fflush(i32* %7)
%33 = tail call i32 @fclose(i32* %7)
%34 = load i32, i32* @stdin
%35 = tail call i64 @feof(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %30
%38 = load i32, i32* @stdin
%39 = tail call i32 @clearerr(i32 %38)
br label %40
40: ; preds = %37, %30
%41 = tail call i32 @free(i8* %2)
%42 = sdiv i64 %31, 1024
%43 = trunc i64 %42 to i32
br label %44
44: ; preds = %40, %13, %4
%45 = phi i32 [ %43, %40 ], [ -1, %13 ], [ -1, %4 ]
ret i32 %45
}