#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof2(long, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isdigit(char);
scalar_t__ isspace(char);
char read_char2(char *, long *, long);
int /*<<< orphan*/ stderr;
int fread_num2(char *buf, int bps, char *buffer, long *pos, long size) {
  int mode, j2, j3;
  char c1;
  for (j2 = 0; j2 < bps; j2++)
    buf[j2] = 0;
  for (mode = 0; !feof2(*pos, size);) {
    c1 = read_char2(buffer, pos, size);
    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/devsarr/ONLYOFFICE-OnlineEditors/refs/"
              "heads/master/ActiveX/ASCOfficeUtils/GOCR/src/pnm.c"
              " L%d: ",
              328);
      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_num2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <fread_num2+0x48>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1182 <fread_num2+0x22>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <feof2@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d4 <fread_num2+0x74>
jmp    12d7 <fread_num2+0x177>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <read_char2@plt>
mov    %al,-0x35(%rbp)
movsbl -0x35(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     120f <fread_num2+0xaf>
cmpl   $0x0,-0x2c(%rbp)
jne    120a <fread_num2+0xaa>
jmp    11af <fread_num2+0x4f>
jmp    12d7 <fread_num2+0x177>
movl   $0x1,-0x2c(%rbp)
movsbl -0x35(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    1265 <fread_num2+0x105>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x148,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12c0 <fread_num2+0x160>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
imul   $0xa,%eax,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1273 <fread_num2+0x113>
movsbl -0x35(%rbp),%edx
sub    $0x30,%edx
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
add    %edx,%ecx
mov    %cl,(%rax)
jmp    11af <fread_num2+0x4f>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_num2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,0x20(%rsp)
mov    %rdi,%rbp
mov    %esi,%ebx
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    11a3 <fread_num2+0x33>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    %rbx,0x10(%rsp)
mov    (%r12),%rdi
mov    %r15,%rsi
call   1030 <feof2@plt>
test   %eax,%eax
je     11c9 <fread_num2+0x59>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rax
and    $0xfffffffe,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%bl
jmp    1205 <fread_num2+0x95>
nopw   0x0(%rax,%rax,1)
add    0x0(%rbp),%r13b
add    $0xd0,%r13b
mov    %r13b,0x0(%rbp)
mov    %rbx,%rax
test   %rax,%rax
setne  %bl
mov    (%r12),%rdi
mov    %r15,%rsi
call   1030 <feof2@plt>
test   %eax,%eax
jne    11b8 <fread_num2+0x48>
mov    0x20(%rsp),%rdi
mov    %r12,%r14
mov    %r12,%rsi
mov    %r15,%r12
mov    %r15,%rdx
call   1070 <read_char2@plt>
mov    %eax,%r13d
movsbl %al,%r15d
mov    %r15d,%edi
call   1060 <isspace@plt>
test   %rax,%rax
je     1240 <fread_num2+0xd0>
test   $0x1,%bl
mov    %r12,%r15
mov    %r14,%r12
jne    11ef <fread_num2+0x7f>
jmp    11b8 <fread_num2+0x48>
nop
mov    %rax,%rbx
mov    %r15d,%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     12cb <fread_num2+0x15b>
cmpl   $0x0,0xc(%rsp)
mov    %r12,%r15
mov    %r14,%r12
jle    11e0 <fread_num2+0x70>
cmpl   $0x1,0xc(%rsp)
jne    126e <fread_num2+0xfe>
xor    %eax,%eax
xor    %ecx,%ecx
mov    0x10(%rsp),%rsi
jmp    12ad <fread_num2+0x13d>
xor    %eax,%eax
xor    %ecx,%ecx
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdi
nopl   0x0(%rax)
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,%rdi
jne    1280 <fread_num2+0x110>
test   $0x1,%sil
je     11e0 <fread_num2+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_num2+0x70>
mov    0x2d0e(%rip),%rbx
mov    (%rbx),%edi
lea    0xd25(%rip),%rsi
mov    $0x148,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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