#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*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isdigit(char);
scalar_t__ isspace(char);
char read_char(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int fread_num(char *buf, int bps, FILE *f1) {
  int mode, j2, j3;
  char c1;
  for (j2 = 0; j2 < bps; j2++)
    buf[j2] = 0;
  for (mode = 0; !feof(f1);) {
    c1 = read_char(f1);
    if (isspace(c1)) {
      if (mode == 0)
        continue;
      else
        break;
    }
    mode = 1;
    if (!isdigit(c1)) {
      fprintf(stderr,
              "\nERROR "
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/AsherBond/MondocosmOS/refs/heads/"
              "master/3rdparty/3dtk-1.2/3rdparty/gocr-0.48/src/pnm.c"
              " L%d: ",
              269);
      fprintf(stderr, "unexpected char"
                      "\n");
      exit(1);
    };
    for (j3 = j2 = 0; j2 < bps; j2++) {
      j3 = buf[j2] * 10 + j3;
      buf[j2] = j3 & 255;
      j3 >>= 8;
    }
    buf[0] += c1 - '0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<fread_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a0 <fread_num+0x40>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117a <fread_num+0x1a>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c5 <fread_num+0x65>
jmp    12c0 <fread_num+0x160>
mov    -0x18(%rbp),%rdi
call   1070 <read_char@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11f8 <fread_num+0x98>
cmpl   $0x0,-0x1c(%rbp)
jne    11f3 <fread_num+0x93>
jmp    11a7 <fread_num+0x47>
jmp    12c0 <fread_num+0x160>
movl   $0x1,-0x1c(%rbp)
movsbl -0x25(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    124e <fread_num+0xee>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    $0x10d,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a9 <fread_num+0x149>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
imul   $0xa,%eax,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    125c <fread_num+0xfc>
movsbl -0x25(%rbp),%edx
sub    $0x30,%edx
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
add    %edx,%ecx
mov    %cl,(%rax)
jmp    11a7 <fread_num+0x47>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rdi,%rbp
mov    %esi,%r14d
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    119c <fread_num+0x2c>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %r14,0x8(%rsp)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11be <fread_num+0x4e>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%r14
and    $0xfffffffe,%r14d
mov    $0x1,%r12b
mov    %rbx,0x10(%rsp)
jmp    1201 <fread_num+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    0x0(%rbp),%bl
add    $0xd0,%bl
mov    %bl,0x0(%rbp)
mov    0x10(%rsp),%rbx
test   %r13,%r13
setne  %r12b
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11ad <fread_num+0x3d>
mov    %rbx,%rdi
call   1080 <read_char@plt>
mov    %eax,%ebx
movsbl %al,%r15d
mov    %r15d,%edi
call   1050 <isspace@plt>
mov    %rax,%r13
test   %rax,%rax
je     1230 <fread_num+0xc0>
test   $0x1,%r12b
mov    0x10(%rsp),%rbx
jne    11ee <fread_num+0x7e>
jmp    11ad <fread_num+0x3d>
nopl   0x0(%rax)
mov    %r15d,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12ac <fread_num+0x13c>
cmpl   $0x0,0x4(%rsp)
jle    11e0 <fread_num+0x70>
cmpl   $0x1,0x4(%rsp)
jne    1250 <fread_num+0xe0>
xor    %eax,%eax
xor    %ecx,%ecx
jmp    128d <fread_num+0x11d>
xor    %eax,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x0(%rbp,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
lea    (%rcx,%rdx,2),%ecx
mov    %cl,0x0(%rbp,%rax,1)
sar    $0x8,%ecx
movsbl 0x1(%rbp,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
lea    (%rcx,%rdx,2),%ecx
mov    %cl,0x1(%rbp,%rax,1)
sar    $0x8,%ecx
add    $0x2,%rax
cmp    %rax,%r14
jne    1260 <fread_num+0xf0>
testb  $0x1,0x8(%rsp)
je     11e0 <fread_num+0x70>
movzbl 0x0(%rbp,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
lea    (%rcx,%rdx,2),%ecx
mov    %cl,0x0(%rbp,%rax,1)
jmp    11e0 <fread_num+0x70>
mov    0x2d2d(%rip),%rbx
mov    (%rbx),%edi
lea    0xd44(%rip),%rsi
mov    $0x10d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xded(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [190 x i8] c"\0AERROR /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AsherBond/MondocosmOS/refs/heads/master/3rdparty/3dtk-1.2/3rdparty/gocr-0.48/src/pnm.c L%d: \00"
@.str.1 = [17 x i8] c"unexpected char\0A\00"
define i32 @fread_num(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %8
br label %11
11: ; preds = %20, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %11
23: ; preds = %11
store i32 0, i32* %7
br label %24
24: ; preds = %77, %38, %23
%25 = load i32*, i32** %6
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %87
29: ; preds = %24
%30 = load i32*, i32** %6
%31 = call signext i8 @read_char(i32* %30)
store i8 %31, i8* %10
%32 = load i8, i8* %10
%33 = call i64 @isspace(i8 signext %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
br label %24
39: ; preds = %35
br label %87
40: ; preds = %29
store i32 1, i32* %7
%41 = load i8, i8* %10
%42 = call i32 @isdigit(i8 signext %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([190 x i8], [190 x i8]* @.str, i64 0, i64 0), i32 269)
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %40
store i32 0, i32* %8
store i32 0, i32* %9
br label %51
51: ; preds = %74, %50
%52 = load i32, i32* %8
%53 = load i32, i32* %5
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %77
55: ; preds = %51
%56 = load i8*, i8** %4
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = mul nsw i32 %61, 10
%63 = load i32, i32* %9
%64 = add nsw i32 %62, %63
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = and i32 %65, 255
%67 = trunc i32 %66 to i8
%68 = load i8*, i8** %4
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 %67, i8* %71
%72 = load i32, i32* %9
%73 = ashr i32 %72, 8
store i32 %73, i32* %9
br label %74
74: ; preds = %55
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %51
77: ; preds = %51
%78 = load i8, i8* %10
%79 = sext i8 %78 to i32
%80 = sub nsw i32 %79, 48
%81 = load i8*, i8** %4
%82 = getelementptr inbounds i8, i8* %81, i64 0
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = add nsw i32 %84, %80
%86 = trunc i32 %85 to i8
store i8 %86, i8* %82
br label %24
87: ; preds = %39, %24
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [190 x i8] c"\0AERROR /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AsherBond/MondocosmOS/refs/heads/master/3rdparty/3dtk-1.2/3rdparty/gocr-0.48/src/pnm.c L%d: \00"
@.str.1 = [17 x i8] c"unexpected char\0A\00"
define i32 @fread_num(i8* nocapture %0, i32 %1, i32* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %3
%8 = tail call i32 @feof(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %73
10: ; preds = %7
%11 = zext i32 %1 to i64
%12 = and i64 %11, 1
%13 = icmp eq i32 %1, 1
%14 = and i64 %11, 4294967294
%15 = icmp eq i64 %12, 0
br label %16
16: ; preds = %10, %69
%17 = phi i1 [ true, %10 ], [ %70, %69 ]
%18 = tail call signext i8 @read_char(i32* %2)
%19 = tail call i64 @isspace(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %16
br i1 %17, label %69, label %73
22: ; preds = %16
%23 = tail call i32 @isdigit(i8 signext %18)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
br i1 %4, label %26, label %65
26: ; preds = %25
br i1 %13, label %55, label %33
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([190 x i8], [190 x i8]* @.str, i64 0, i64 0), i32 269)
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26, %33
%34 = phi i64 [ %52, %33 ], [ 0, %26 ]
%35 = phi i32 [ %51, %33 ], [ 0, %26 ]
%36 = phi i64 [ %53, %33 ], [ 0, %26 ]
%37 = getelementptr inbounds i8, i8* %0, i64 %34
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = mul nsw i32 %39, 10
%41 = add nsw i32 %40, %35
%42 = trunc i32 %41 to i8
store i8 %42, i8* %37
%43 = ashr i32 %41, 8
%44 = or i64 %34, 1
%45 = getelementptr inbounds i8, i8* %0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = mul nsw i32 %47, 10
%49 = add nsw i32 %48, %43
%50 = trunc i32 %49 to i8
store i8 %50, i8* %45
%51 = ashr i32 %49, 8
%52 = add nuw nsw i64 %34, 2
%53 = add i64 %36, 2
%54 = icmp eq i64 %53, %14
br i1 %54, label %55, label %33
55: ; preds = %33, %26
%56 = phi i64 [ 0, %26 ], [ %52, %33 ]
%57 = phi i32 [ 0, %26 ], [ %51, %33 ]
br i1 %15, label %65, label %58
58: ; preds = %55
%59 = getelementptr inbounds i8, i8* %0, i64 %56
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = mul nsw i32 %61, 10
%63 = add nsw i32 %62, %57
%64 = trunc i32 %63 to i8
store i8 %64, i8* %59
br label %65
65: ; preds = %58, %55, %25
%66 = add i8 %18, -48
%67 = load i8, i8* %0
%68 = add i8 %66, %67
store i8 %68, i8* %0
br label %69
69: ; preds = %65, %21
%70 = xor i1 %20, true
%71 = tail call i32 @feof(i32* %2)
%72 = icmp eq i32 %71, 0
br i1 %72, label %16, label %73
73: ; preds = %69, %21, %7
ret i32 0
}