#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
scalar_t__ isdigit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int main(void) {
  int c, number;
  FILE *fp;
  if ((fp = fopen("test.txt", "r")) == NULL) {
    perror("File open error");
    exit(-1);
  }
  while (!feof(fp)) {
    c = fgetc(fp);
    if (c == '\n')
      continue;
    else if (isdigit(c)) {
      number = c - '0';
      while ((c = fgetc(fp)) != EOF && isdigit(c))
        number = 10 * number + c - '0';
      fprintf(stdout, "Operand => %d\n", number);
      ungetc(c, fp);
    } else
      fprintf(stdout, "Operator => %c\n", (char)c);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d6 <main+0x46>
lea    0xe42(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    11db <main+0x4b>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <main+0x69>
jmp    12d6 <main+0x146>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    1214 <main+0x84>
jmp    11db <main+0x4b>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12b1 <main+0x121>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
mov    0x2da2(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1263 <main+0xd3>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1273 <main+0xe3>
jmp    1285 <main+0xf5>
imul   $0xa,-0xc(%rbp),%eax
add    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    122f <main+0x9f>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%eax
lea    0xd81(%rip),%rsi
movsbl %al,%edx
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <ungetc@plt>
jmp    12cc <main+0x13c>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%eax
lea    0xd64(%rip),%rsi
movsbl %al,%edx
call   1060 <fprintf@plt>
jmp    12d1 <main+0x141>
jmp    11db <main+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128f <main+0xff>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11df <main+0x4f>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df2(%rip),%rbp
mov    0x2dfb(%rip),%r14
lea    0xe25(%rip),%r15
jmp    1225 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
movsbl %r13b,%edx
mov    %r15,%rsi
call   1060 <fprintf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
call   1080 <ungetc@plt>
mov    %r12,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11c6 <main+0x36>
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
je     1219 <main+0x89>
mov    %eax,%r13d
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     127a <main+0xea>
add    $0xffffffd0,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
je     1200 <main+0x70>
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1200 <main+0x70>
lea    0x0(%r13,%r13,4),%eax
lea    (%rbx,%rax,2),%r13d
add    $0xffffffd0,%r13d
jmp    1250 <main+0xc0>
mov    0x0(%rbp),%edi
movsbl %r13b,%edx
lea    0xda0(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1219 <main+0x89>
lea    0xd73(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"File open error\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [15 x i8] c"Operand => %d\0A\00"
@.str.4 = [16 x i8] c"Operator => %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %60, %21, %10
%12 = load i32*, i32** %4
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %61
16: ; preds = %11
%17 = load i32*, i32** %4
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %16
br label %11
22: ; preds = %16
%23 = load i32, i32* %2
%24 = call i64 @isdigit(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %54
26: ; preds = %22
%27 = load i32, i32* %2
%28 = sub nsw i32 %27, 48
store i32 %28, i32* %3
br label %29
29: ; preds = %40, %26
%30 = load i32*, i32** %4
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %2
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %2
%36 = call i64 @isdigit(i32 %35)
%37 = icmp ne i64 %36, 0
br label %38
38: ; preds = %34, %29
%39 = phi i1 [ false, %29 ], [ %37, %34 ]
br i1 %39, label %40, label %46
40: ; preds = %38
%41 = load i32, i32* %3
%42 = mul nsw i32 10, %41
%43 = load i32, i32* %2
%44 = add nsw i32 %42, %43
%45 = sub nsw i32 %44, 48
store i32 %45, i32* %3
br label %29
46: ; preds = %38
%47 = load i32, i32* @stdout
%48 = load i32, i32* %3
%49 = trunc i32 %48 to i8
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8 signext %49)
%51 = load i32, i32* %2
%52 = load i32*, i32** %4
%53 = call i32 @ungetc(i32 %51, i32* %52)
br label %59
54: ; preds = %22
%55 = load i32, i32* @stdout
%56 = load i32, i32* %2
%57 = trunc i32 %56 to i8
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8 signext %57)
br label %59
59: ; preds = %54, %46
br label %60
60: ; preds = %59
br label %11
61: ; preds = %11
%62 = load i32*, i32** %4
%63 = call i32 @fclose(i32* %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"File open error\00"
@EOF = global i32 0
@stdout = global i32 0
@.str.3 = [15 x i8] c"Operand => %d\0A\00"
@.str.4 = [16 x i8] c"Operator => %c\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @feof(i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %46
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %3, %43
%10 = tail call i32 @fgetc(i32* %1)
%11 = icmp eq i32 %10, 10
br i1 %11, label %43, label %12
12: ; preds = %9
%13 = tail call i64 @isdigit(i32 %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %39, label %15
15: ; preds = %12
%16 = add nsw i32 %10, -48
%17 = tail call i32 @fgetc(i32* %1)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %32, label %20
20: ; preds = %15, %25
%21 = phi i32 [ %29, %25 ], [ %17, %15 ]
%22 = phi i32 [ %28, %25 ], [ %16, %15 ]
%23 = tail call i64 @isdigit(i32 %21)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %20
%26 = mul nsw i32 %22, 10
%27 = add nsw i32 %26, %21
%28 = add nsw i32 %27, -48
%29 = tail call i32 @fgetc(i32* %1)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %20
32: ; preds = %20, %25, %15
%33 = phi i32 [ %16, %15 ], [ %28, %25 ], [ %22, %20 ]
%34 = phi i32 [ %17, %15 ], [ %29, %25 ], [ %21, %20 ]
%35 = load i32, i32* @stdout
%36 = trunc i32 %33 to i8
%37 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8 signext %36)
%38 = tail call i32 @ungetc(i32 %34, i32* %1)
br label %43
39: ; preds = %12
%40 = load i32, i32* @stdout
%41 = trunc i32 %10 to i8
%42 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8 signext %41)
br label %43
43: ; preds = %39, %32, %9
%44 = tail call i32 @feof(i32* %1)
%45 = icmp eq i32 %44, 0
br i1 %45, label %9, label %46
46: ; preds = %43, %3
%47 = tail call i32 @fclose(i32* %1)
ret i32 0
}