#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_CUR;
char calculate(double, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ isdigit(char);
int fileprocess(FILE *stream, char *expression) {
  double res = 0;
  int end = 0;
  char c;
  FILE *streamout = NULL;
  streamout = fopen("./tempprocess", "w");
  while ((fscanf(stream, "%c", &c) != EOF) && end != 1) {
    while (!isdigit(c) && !(c == 46) && !(c == 45)) {
      fprintf(streamout, "%c", c);
      if (fscanf(stream, "%c", &c) == EOF) {
        end = 1;
        c = '1';
      }
    }
    fseek(stream, -1 * sizeof(char), SEEK_CUR);
    if (fscanf(stream, "%lf", &res) == EOF) {
      end = 1;
      c = '1';
    }
    if (end != 1) {
      fprintf(streamout, "%lf", calculate(res, expression));
    }
  }
  fclose(streamout);
  return 1;
}


x86 assembly (clang, -O0):
<fileprocess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe62(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe57(%rip),%rsi
lea    -0x1d(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e10(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x29(%rbp)
je     11e6 <fileprocess+0x76>
cmpl   $0x1,-0x1c(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f6 <fileprocess+0x86>
jmp    130f <fileprocess+0x19f>
jmp    11fb <fileprocess+0x8b>
movsbl -0x1d(%rbp),%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2a(%rbp)
jne    1235 <fileprocess+0xc5>
movsbl -0x1d(%rbp),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x2a(%rbp)
je     1235 <fileprocess+0xc5>
movsbl -0x1d(%rbp),%eax
cmp    $0x2d,%eax
sete   %al
xor    $0xff,%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1245 <fileprocess+0xd5>
jmp    128f <fileprocess+0x11f>
mov    -0x28(%rbp),%rdi
lea    0xdc0(%rip),%rsi
movsbl -0x1d(%rbp),%edx
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdac(%rip),%rsi
lea    -0x1d(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    0x2d6a(%rip),%rcx
cmp    (%rcx),%rax
jne    128a <fileprocess+0x11a>
movl   $0x1,-0x1c(%rbp)
movb   $0x31,-0x1d(%rbp)
jmp    11fb <fileprocess+0x8b>
mov    -0x8(%rbp),%rdi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1080 <fseek@plt>
mov    -0x8(%rbp),%rdi
lea    0xd62(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    0x2d1d(%rip),%rcx
cmp    (%rcx),%rax
jne    12d7 <fileprocess+0x167>
movl   $0x1,-0x1c(%rbp)
movb   $0x31,-0x1d(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     130a <fileprocess+0x19a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rdi
call   1050 <calculate@plt>
mov    -0x38(%rbp),%rdi
lea    0xd11(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
jmp    11ae <fileprocess+0x3e>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileprocess>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xe5a(%rip),%rdi
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe54(%rip),%rsi
lea    0x7(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
je     1305 <fileprocess+0x185>
lea    0xe2e(%rip),%r13
lea    0x7(%rsp),%r14
nopw   0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%edi
call   1030 <isdigit@plt>
mov    $0x0,%r12d
test   %eax,%eax
mov    0x2dd7(%rip),%rbp
jne    126e <fileprocess+0xee>
mov    0x7(%rsp),%al
lea    -0x2d(%rax),%ecx
mov    $0x0,%r12d
cmp    $0x2,%cl
jb     126e <fileprocess+0xee>
xor    %r12d,%r12d
movsbl %al,%edi
mov    %r15,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    0x0(%rbp),%rax
jne    1250 <fileprocess+0xd0>
movb   $0x31,0x7(%rsp)
mov    $0x1,%r12d
mov    $0x31,%al
jmp    1255 <fileprocess+0xd5>
movzbl 0x7(%rsp),%eax
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    126e <fileprocess+0xee>
movzbl 0x7(%rsp),%eax
lea    -0x2d(%rax),%ecx
cmp    $0x1,%cl
ja     1220 <fileprocess+0xa0>
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
lea    0xd85(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
cmp    0x0(%rbp),%rax
jne    12b0 <fileprocess+0x130>
movb   $0x31,0x7(%rsp)
mov    $0x1,%ebp
jmp    12e0 <fileprocess+0x160>
nopl   0x0(%rax)
mov    $0x1,%ebp
cmp    $0x1,%r12d
je     12e0 <fileprocess+0x160>
movsd  0x8(%rsp),%xmm0
mov    0x10(%rsp),%rdi
call   1050 <calculate@plt>
movsbl %al,%edx
mov    %r15,%rdi
lea    0xd3b(%rip),%rsi
call   1080 <fprintf@plt>
mov    %r12d,%ebp
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%rax
je     1305 <fileprocess+0x185>
cmp    $0x1,%ebp
jne    11f0 <fileprocess+0x70>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"./tempprocess\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i64 0
@SEEK_CUR = global i32 0
@.str.3 = [4 x i8] c"%lf\00"
define i32 @fileprocess(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
store i32* null, i32** %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
br label %10
10: ; preds = %64, %2
%11 = load i32*, i32** %3
%12 = call i64 (i32*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%13 = load i64, i64* @EOF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 1
br label %18
18: ; preds = %15, %10
%19 = phi i1 [ false, %10 ], [ %17, %15 ]
br i1 %19, label %20, label %65
20: ; preds = %18
br label %21
21: ; preds = %45, %20
%22 = load i8, i8* %7
%23 = call i32 @isdigit(i8 signext %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %21
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 46
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
%33 = xor i1 %32, true
br label %34
34: ; preds = %29, %25, %21
%35 = phi i1 [ false, %25 ], [ false, %21 ], [ %33, %29 ]
br i1 %35, label %36, label %46
36: ; preds = %34
%37 = load i32*, i32** %8
%38 = load i8, i8* %7
%39 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %38)
%40 = load i32*, i32** %3
%41 = call i64 (i32*, i8*, ...) @fscanf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%42 = load i64, i64* @EOF
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %36
store i32 1, i32* %6
store i8 49, i8* %7
br label %45
45: ; preds = %44, %36
br label %21
46: ; preds = %34
%47 = load i32*, i32** %3
%48 = load i32, i32* @SEEK_CUR
%49 = call i32 @fseek(i32* %47, i32 -1, i32 %48)
%50 = load i32*, i32** %3
%51 = call i64 (i32*, i8*, ...) @fscanf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %5)
%52 = load i64, i64* @EOF
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %46
store i32 1, i32* %6
store i8 49, i8* %7
br label %55
55: ; preds = %54, %46
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = load i32*, i32** %8
%60 = load double, double* %5
%61 = load i8*, i8** %4
%62 = call signext i8 @calculate(double %60, i8* %61)
%63 = call i32 @fprintf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %62)
br label %64
64: ; preds = %58, %55
br label %10
65: ; preds = %18
%66 = load i32*, i32** %8
%67 = call i32 @fclose(i32* %66)
ret i32 1
}

LLVM IR (-O2):
@.str = [14 x i8] c"./tempprocess\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i64 0
@SEEK_CUR = global i32 0
@.str.3 = [4 x i8] c"%lf\00"
define i32 @fileprocess(i32* nocapture %0, i8* %1) {
%3 = alloca double
%4 = alloca i8
%5 = bitcast double* %3 to i8*
store double 0.000000e+00, double* %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %61, label %10
10: ; preds = %2, %54
%11 = load i8, i8* %4
%12 = call i32 @isdigit(i8 signext %11)
%13 = freeze i32 %12
%14 = icmp ne i32 %13, 0
%15 = load i8, i8* %4
%16 = add i8 %15, -45
%17 = icmp ult i8 %16, 2
%18 = select i1 %14, i1 true, i1 %17
br i1 %18, label %40, label %19
19: ; preds = %10, %30
%20 = phi i8 [ %36, %30 ], [ %15, %10 ]
%21 = phi i32 [ %32, %30 ], [ 0, %10 ]
%22 = sext i8 %20 to i32
%23 = call i32 @fputc(i32 %22, i32* %6)
%24 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %19
%28 = load i8, i8* %4
br label %30
29: ; preds = %19
store i8 49, i8* %4
br label %30
30: ; preds = %27, %29
%31 = phi i8 [ 49, %29 ], [ %28, %27 ]
%32 = phi i32 [ 1, %29 ], [ %21, %27 ]
%33 = call i32 @isdigit(i8 signext %31)
%34 = freeze i32 %33
%35 = icmp ne i32 %34, 0
%36 = load i8, i8* %4
%37 = add i8 %36, -45
%38 = icmp ult i8 %37, 2
%39 = select i1 %35, i1 true, i1 %38
br i1 %39, label %40, label %19
40: ; preds = %30, %10
%41 = phi i32 [ 0, %10 ], [ %32, %30 ]
%42 = load i32, i32* @SEEK_CUR
%43 = call i32 @fseek(i32* %0, i32 -1, i32 %42)
%44 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%45 = load i64, i64* @EOF
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %40
store i8 49, i8* %4
br label %54
48: ; preds = %40
%49 = icmp eq i32 %41, 1
br i1 %49, label %54, label %50
50: ; preds = %48
%51 = load double, double* %3
%52 = call signext i8 @calculate(double %51, i8* %1)
%53 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %52)
br label %54
54: ; preds = %47, %50, %48
%55 = phi i32 [ 1, %47 ], [ %41, %50 ], [ 1, %48 ]
%56 = call i64 (i32*, i8*, ...) @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%57 = load i64, i64* @EOF
%58 = icmp ne i64 %56, %57
%59 = icmp ne i32 %55, 1
%60 = select i1 %58, i1 %59, i1 false
br i1 %60, label %10, label %61
61: ; preds = %54, %2
%62 = call i32 @fclose(i32* %6)
ret i32 1
}