#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 EXIT_FAILURE;
int /*<<< orphan*/ evaluate(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int getopt(int, char **, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *optarg;
scalar_t__ opterr;
int optind;
char optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *fin = stdin;
  FILE *fout = stdout;
  int standardio = 1;
  int eflag = 0;
  int fflag = 0;
  char *expr = NULL;
  opterr = 0;
  int c = 0;
  while ((c = getopt(argc, argv, "hf:o:e:")) != -1) {
    switch (c) {
    case 'h':
      fprintf(
          fout,
          "usage: calc [-f input_file] [-o output_file] [-e] [expression] "
          "...\nOptions and arguments:\n-f     : specify the input file\n-o    "
          " : specify the output file\n-e     : enable the Evaluating mode\n-h "
          "    : print this help message and exit\n\nExpressions output:\n    "
          "If the input or output is not given by the standard i/o, the "
          "expressions\n    themselves would also be printed.\n    The "
          "expressions would also be printed under the Evaluating mode.\n");
      return 0;
    case 'e':
      eflag = 1;
      expr = optarg;
      break;
    case 'f':
      fin = fopen(optarg, "r");
      if (!fin) {
        perror("file opening failed");
        return EXIT_FAILURE;
      }
      standardio = 0;
      break;
    case 'o':
      fout = fopen(optarg, "w");
      if (!fout) {
        perror("file opening failed");
        return EXIT_FAILURE;
      }
      standardio = 0;
      break;
    case '?':
      if (optopt == 'e')
        fprintf(stderr, "Evaluating mode requires at least an expression\n");
      else if (optopt == 'f')
        fprintf(stderr, "No input file\n");
      else if (optopt == 'o')
        fprintf(stderr, "No output file\n");
      else
        fprintf(stderr, "Option Error\n");
      return EXIT_FAILURE;
    default:
      fprintf(stderr, "Unknown error\n");
      return EXIT_FAILURE;
    }
  }
  if (eflag) {
    fprintf(fout, "%s = ", expr);
    if (!evaluate(fout, expr)) {
      fprintf(stderr, "Evaluation failed\n");
    }
    int i = optind;
    while (i != argc) {
      expr = argv[i];
      fprintf(fout, "%s = ", expr);
      if (!evaluate(fout, expr)) {
        fprintf(stderr, "Evaluation failed\n");
      }
      ++i;
    }
  } else {
    if (standardio) {
      fprintf(fout, "A Stupid Calc\n");
    }
    if (optind != argc) {
      fprintf(fout, "The expressions in the parameters are ignored.\n");
    }
    expr = malloc(sizeof(char) * 2048);
    while (1) {
      if (standardio) {
        fprintf(fout, ">>> ");
      }
      memset(expr, 0, sizeof(char) * 2048);
      if (fscanf(fin, "%s", expr) != EOF) {
        if (!standardio) {
          fprintf(fout, "%s = ", expr);
        }
        if (!evaluate(fout, expr)) {
          fprintf(stderr, "Evaluation failed\n");
        }
      } else {
        if (standardio) {
          fprintf(fout, "exit\n");
        }
        break;
      }
    }
    free(expr);
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2db2(%rip),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb2(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     1411 <main+0x271>
mov    -0x3c(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x30,%eax
ja     13e3 <main+0x243>
mov    -0x48(%rbp),%rax
lea    0xdbd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1617 <main+0x477>
movl   $0x1,-0x28(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    140c <main+0x26c>
mov    0x2d6d(%rip),%rax
mov    (%rax),%rdi
lea    0xfee(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12c6 <main+0x126>
lea    0xfd5(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1617 <main+0x477>
movl   $0x0,-0x24(%rbp)
jmp    140c <main+0x26c>
mov    0x2d1f(%rip),%rax
mov    (%rax),%rdi
lea    0xfb6(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1314 <main+0x174>
lea    0xf87(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1617 <main+0x477>
movl   $0x0,-0x24(%rbp)
jmp    140c <main+0x26c>
mov    0x2cb1(%rip),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
jne    1350 <main+0x1b0>
mov    0x2c7e(%rip),%rax
mov    (%rax),%rdi
lea    0xf57(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13d2 <main+0x232>
mov    0x2c81(%rip),%rax
movsbl (%rax),%eax
cmp    $0x66,%eax
jne    1380 <main+0x1e0>
mov    0x2c4e(%rip),%rax
mov    (%rax),%rdi
lea    0xf58(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13cd <main+0x22d>
mov    0x2c51(%rip),%rax
movsbl (%rax),%eax
cmp    $0x6f,%eax
jne    13b0 <main+0x210>
mov    0x2c1e(%rip),%rax
mov    (%rax),%rdi
lea    0xf37(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13c8 <main+0x228>
mov    0x2c01(%rip),%rax
mov    (%rax),%rdi
lea    0xf2a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13cd <main+0x22d>
jmp    13d2 <main+0x232>
mov    0x2bd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1617 <main+0x477>
mov    0x2bce(%rip),%rax
mov    (%rax),%rdi
lea    0xf05(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2bae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1617 <main+0x477>
jmp    1204 <main+0x64>
cmpl   $0x0,-0x28(%rbp)
je     14de <main+0x33e>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xede(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <evaluate@plt>
cmp    $0x0,%eax
jne    145f <main+0x2bf>
mov    0x2b6a(%rip),%rax
mov    (%rax),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2b62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     14d9 <main+0x339>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <evaluate@plt>
cmp    $0x0,%eax
jne    14cb <main+0x32b>
mov    0x2afe(%rip),%rax
mov    (%rax),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    146b <main+0x2cb>
jmp    15fe <main+0x45e>
cmpl   $0x0,-0x24(%rbp)
je     14fa <main+0x35a>
mov    -0x20(%rbp),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
je     151e <main+0x37e>
mov    -0x20(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x800,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1548 <main+0x3a8>
mov    -0x20(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdfe(%rip),%rsi
call   1060 <fscanf@plt>
mov    0x2a5d(%rip),%rcx
cmp    (%rcx),%rax
je     15cf <main+0x42f>
cmpl   $0x0,-0x24(%rbp)
jne    159c <main+0x3fc>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <evaluate@plt>
cmp    $0x0,%eax
jne    15ca <main+0x42a>
mov    0x29ff(%rip),%rax
mov    (%rax),%rdi
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15f0 <main+0x450>
cmpl   $0x0,-0x24(%rbp)
je     15eb <main+0x44b>
mov    -0x20(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    15f5 <main+0x455>
jmp    152c <main+0x38c>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %edi,%r12d
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x2dbf(%rip),%rax
movq   $0x0,(%rax)
xor    %r15d,%r15d
mov    $0x1,%r14d
lea    0xe00(%rip),%rbp
xor    %ebx,%ebx
jmp    1220 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2de1(%rip),%rax
mov    (%rax),%rbx
mov    $0x1,%r15d
mov    %r12d,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10c0 <getopt@plt>
cmp    $0x65,%eax
je     1210 <main+0x60>
jle    129c <main+0xec>
cmp    $0x66,%eax
je     1268 <main+0xb8>
cmp    $0x6f,%eax
jne    12e6 <main+0x136>
mov    0x2dae(%rip),%rax
mov    (%rax),%rdi
lea    0xf81(%rip),%rsi
call   10a0 <fopen@plt>
xor    %r14d,%r14d
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    1220 <main+0x70>
jmp    128b <main+0xdb>
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
lea    0xf46(%rip),%rsi
call   10a0 <fopen@plt>
xor    %r14d,%r14d
mov    %rax,0x10(%rsp)
test   %rax,%rax
jne    1220 <main+0x70>
lea    0xf2f(%rip),%rdi
call   10b0 <perror@plt>
jmp    1412 <main+0x262>
cmp    $0xffffffff,%eax
je     130f <main+0x15f>
cmp    $0x3f,%eax
jne    13f2 <main+0x242>
mov    0x2d27(%rip),%rax
mov    (%rax),%al
cmp    $0x6f,%al
je     156b <main+0x3bb>
cmp    $0x66,%al
je     1586 <main+0x3d6>
cmp    $0x65,%al
jne    159c <main+0x3ec>
mov    0x2ce6(%rip),%rax
mov    (%rax),%rcx
lea    0xefb(%rip),%rdi
mov    $0x30,%esi
jmp    1408 <main+0x258>
cmp    $0x68,%eax
jne    13f2 <main+0x242>
lea    0xd12(%rip),%rdi
mov    $0x1b6,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
jmp    155a <main+0x3aa>
test   %r15d,%r15d
je     1420 <main+0x270>
lea    0xf25(%rip),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <evaluate@plt>
test   %eax,%eax
jne    1360 <main+0x1b0>
mov    0x2c71(%rip),%rax
mov    (%rax),%rcx
lea    0xef9(%rip),%rdi
mov    $0x12,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    0x2c61(%rip),%rax
movslq (%rax),%rax
cmp    %r12d,%eax
je     1546 <main+0x396>
lea    0x0(,%rax,8),%rbx
add    %r13,%rbx
sub    %eax,%r12d
lea    0xebc(%rip),%r14
xor    %r15d,%r15d
mov    0x8(%rsp),%r13
jmp    13ad <main+0x1fd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r15d,%r12d
je     1546 <main+0x396>
mov    (%rbx,%r15,8),%rbp
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <evaluate@plt>
test   %eax,%eax
jne    13a0 <main+0x1f0>
mov    0x2be1(%rip),%rax
mov    (%rax),%rcx
mov    $0x12,%esi
mov    $0x1,%edx
lea    0xe5f(%rip),%rdi
call   10d0 <fwrite@plt>
jmp    13a0 <main+0x1f0>
mov    0x2bbf(%rip),%rax
mov    (%rax),%rcx
lea    0xe32(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%eax
jmp    155c <main+0x3ac>
test   %r14d,%r14d
je     1440 <main+0x290>
lea    0xe31(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
mov    0x2b81(%rip),%rax
cmp    %r12d,(%rax)
je     1467 <main+0x2b7>
lea    0xe19(%rip),%rdi
mov    $0x2f,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
mov    $0x800,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe26(%rip),%r15
mov    0x2b4e(%rip),%rbp
lea    0xdc1(%rip),%r13
lea    0xe0c(%rip),%r12
test   %r14d,%r14d
je     14ac <main+0x2fc>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
mov    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
cmp    0x0(%rbp),%rax
je     151e <main+0x36e>
test   %r14d,%r14d
jne    14ec <main+0x33c>
mov    0x8(%rsp),%rdi
lea    0xd62(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <evaluate@plt>
test   %eax,%eax
jne    1490 <main+0x2e0>
mov    0x2ab4(%rip),%rax
mov    (%rax),%rcx
mov    $0x12,%esi
mov    $0x1,%edx
mov    %r13,%rdi
call   10d0 <fwrite@plt>
jmp    1490 <main+0x2e0>
test   %r14d,%r14d
je     153e <main+0x38e>
lea    0xd7a(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    0x8(%rsp),%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a46(%rip),%rax
mov    (%rax),%rcx
lea    0xc9b(%rip),%rdi
mov    $0xf,%esi
jmp    1408 <main+0x258>
mov    0x2a2b(%rip),%rax
mov    (%rax),%rcx
lea    0xc71(%rip),%rdi
jmp    1403 <main+0x253>
mov    0x2a15(%rip),%rax
mov    (%rax),%rcx
lea    0xc7a(%rip),%rdi
mov    $0xd,%esi
jmp    1408 <main+0x258>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@opterr = global i64 0
@.str = [8 x i8] c"hf:o:e:\00"
@.str.1 = [439 x i8] c"usage: calc [-f input_file] [-o output_file] [-e] [expression] ...\0AOptions and arguments:\0A-f : specify the input file\0A-o : specify the output file\0A-e : enable the Evaluating mode\0A-h : print this help message and exit\0A\0AExpressions output:\0A If the input or output is not given by the standard i/o, the expressions\0A themselves would also be printed.\0A The expressions would also be printed under the Evaluating mode.\0A\00"
@optarg = global i8* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"file opening failed\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [2 x i8] c"w\00"
@optopt = global i8 0
@stderr = global i32* null
@.str.5 = [49 x i8] c"Evaluating mode requires at least an expression\0A\00"
@.str.6 = [15 x i8] c"No input file\0A\00"
@.str.7 = [16 x i8] c"No output file\0A\00"
@.str.8 = [14 x i8] c"Option Error\0A\00"
@.str.9 = [15 x i8] c"Unknown error\0A\00"
@.str.10 = [6 x i8] c"%s = \00"
@.str.11 = [19 x i8] c"Evaluation failed\0A\00"
@optind = global i32 0
@.str.12 = [15 x i8] c"A Stupid Calc\0A\00"
@.str.13 = [48 x i8] c"The expressions in the parameters are ignored.\0A\00"
@.str.14 = [5 x i8] c">>> \00"
@.str.15 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.16 = [6 x i8] c"exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32*, i32** @stdin
store i32* %14, i32** %6
%15 = load i32*, i32** @stdout
store i32* %15, i32** %7
store i32 1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i8* null, i8** %11
store i64 0, i64* @opterr
store i32 0, i32* %12
br label %16
16: ; preds = %78, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %12
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %79
21: ; preds = %16
%22 = load i32, i32* %12
switch i32 %22, label %74 [
i32 104, label %23
i32 101, label %26
i32 102, label %28
i32 111, label %37
i32 63, label %46
]
23: ; preds = %21
%24 = load i32*, i32** %7
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([439 x i8], [439 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %180
26: ; preds = %21
store i32 1, i32* %9
%27 = load i8*, i8** @optarg
store i8* %27, i8** %11
br label %78
28: ; preds = %21
%29 = load i8*, i8** @optarg
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %180
36: ; preds = %28
store i32 0, i32* %8
br label %78
37: ; preds = %21
%38 = load i8*, i8** @optarg
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp ne i32* %40, null
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %180
45: ; preds = %37
store i32 0, i32* %8
br label %78
46: ; preds = %21
%47 = load i8, i8* @optopt
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 101
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i32*, i32** @stderr
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %72
53: ; preds = %46
%54 = load i8, i8* @optopt
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 102
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32*, i32** @stderr
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %71
60: ; preds = %53
%61 = load i8, i8* @optopt
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 111
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32*, i32** @stderr
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %70
67: ; preds = %60
%68 = load i32*, i32** @stderr
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %70
70: ; preds = %67, %64
br label %71
71: ; preds = %70, %57
br label %72
72: ; preds = %71, %50
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %3
br label %180
74: ; preds = %21
%75 = load i32*, i32** @stderr
%76 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %3
br label %180
78: ; preds = %45, %36, %26
br label %16
79: ; preds = %16
%80 = load i32, i32* %9
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %119
82: ; preds = %79
%83 = load i32*, i32** %7
%84 = load i8*, i8** %11
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %83, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %84)
%86 = load i32*, i32** %7
%87 = load i8*, i8** %11
%88 = call i32 @evaluate(i32* %86, i8* %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %93, label %90
90: ; preds = %82
%91 = load i32*, i32** @stderr
%92 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %93
93: ; preds = %90, %82
%94 = load i32, i32* @optind
store i32 %94, i32* %13
br label %95
95: ; preds = %115, %93
%96 = load i32, i32* %13
%97 = load i32, i32* %4
%98 = icmp ne i32 %96, %97
br i1 %98, label %99, label %118
99: ; preds = %95
%100 = load i8**, i8*** %5
%101 = load i32, i32* %13
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
%104 = load i8*, i8** %103
store i8* %104, i8** %11
%105 = load i32*, i32** %7
%106 = load i8*, i8** %11
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %106)
%108 = load i32*, i32** %7
%109 = load i8*, i8** %11
%110 = call i32 @evaluate(i32* %108, i8* %109)
%111 = icmp ne i32 %110, 0
br i1 %111, label %115, label %112
112: ; preds = %99
%113 = load i32*, i32** @stderr
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %115
115: ; preds = %112, %99
%116 = load i32, i32* %13
%117 = add nsw i32 %116, 1
store i32 %117, i32* %13
br label %95
118: ; preds = %95
br label %175
119: ; preds = %79
%120 = load i32, i32* %8
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %125
122: ; preds = %119
%123 = load i32*, i32** %7
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %123, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %125
125: ; preds = %122, %119
%126 = load i32, i32* @optind
%127 = load i32, i32* %4
%128 = icmp ne i32 %126, %127
br i1 %128, label %129, label %132
129: ; preds = %125
%130 = load i32*, i32** %7
%131 = call i32 (i32*, i8*, ...) @fprintf(i32* %130, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0))
br label %132
132: ; preds = %129, %125
%133 = call i8* @malloc(i32 2048)
store i8* %133, i8** %11
br label %134
134: ; preds = %132, %171
%135 = load i32, i32* %8
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %140
137: ; preds = %134
%138 = load i32*, i32** %7
%139 = call i32 (i32*, i8*, ...) @fprintf(i32* %138, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %140
140: ; preds = %137, %134
%141 = load i8*, i8** %11
%142 = call i32 @memset(i8* %141, i32 0, i32 2048)
%143 = load i32*, i32** %6
%144 = load i8*, i8** %11
%145 = call i64 @fscanf(i32* %143, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8* %144)
%146 = load i64, i64* @EOF
%147 = icmp ne i64 %145, %146
br i1 %147, label %148, label %164
148: ; preds = %140
%149 = load i32, i32* %8
%150 = icmp ne i32 %149, 0
br i1 %150, label %155, label %151
151: ; preds = %148
%152 = load i32*, i32** %7
%153 = load i8*, i8** %11
%154 = call i32 (i32*, i8*, ...) @fprintf(i32* %152, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %153)
br label %155
155: ; preds = %151, %148
%156 = load i32*, i32** %7
%157 = load i8*, i8** %11
%158 = call i32 @evaluate(i32* %156, i8* %157)
%159 = icmp ne i32 %158, 0
br i1 %159, label %163, label %160
160: ; preds = %155
%161 = load i32*, i32** @stderr
%162 = call i32 (i32*, i8*, ...) @fprintf(i32* %161, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %163
163: ; preds = %160, %155
br label %171
164: ; preds = %140
%165 = load i32, i32* %8
%166 = icmp ne i32 %165, 0
br i1 %166, label %167, label %170
167: ; preds = %164
%168 = load i32*, i32** %7
%169 = call i32 (i32*, i8*, ...) @fprintf(i32* %168, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0))
br label %170
170: ; preds = %167, %164
br label %172
171: ; preds = %163
br label %134
172: ; preds = %170
%173 = load i8*, i8** %11
%174 = call i32 @free(i8* %173)
br label %175
175: ; preds = %172, %118
%176 = load i32*, i32** %6
%177 = call i32 @fclose(i32* %176)
%178 = load i32*, i32** %7
%179 = call i32 @fclose(i32* %178)
store i32 0, i32* %3
br label %180
180: ; preds = %175, %74, %72, %42, %33, %23
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@opterr = global i64 0
@.str = [8 x i8] c"hf:o:e:\00"
@.str.1 = [439 x i8] c"usage: calc [-f input_file] [-o output_file] [-e] [expression] ...\0AOptions and arguments:\0A-f : specify the input file\0A-o : specify the output file\0A-e : enable the Evaluating mode\0A-h : print this help message and exit\0A\0AExpressions output:\0A If the input or output is not given by the standard i/o, the expressions\0A themselves would also be printed.\0A The expressions would also be printed under the Evaluating mode.\0A\00"
@optarg = global i8* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [20 x i8] c"file opening failed\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [2 x i8] c"w\00"
@optopt = global i8 0
@stderr = global i32* null
@.str.5 = [49 x i8] c"Evaluating mode requires at least an expression\0A\00"
@.str.6 = [15 x i8] c"No input file\0A\00"
@.str.7 = [16 x i8] c"No output file\0A\00"
@.str.8 = [14 x i8] c"Option Error\0A\00"
@.str.9 = [15 x i8] c"Unknown error\0A\00"
@.str.10 = [6 x i8] c"%s = \00"
@.str.11 = [19 x i8] c"Evaluation failed\0A\00"
@optind = global i32 0
@.str.12 = [15 x i8] c"A Stupid Calc\0A\00"
@.str.13 = [48 x i8] c"The expressions in the parameters are ignored.\0A\00"
@.str.14 = [5 x i8] c">>> \00"
@.str.15 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.16 = [6 x i8] c"exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32*, i32** @stdin
%4 = load i32*, i32** @stdout
store i64 0, i64* @opterr
br label %5
5: ; preds = %24, %2
%6 = phi i32* [ %26, %24 ], [ %3, %2 ]
%7 = phi i32* [ %12, %24 ], [ %4, %2 ]
%8 = phi i32 [ 0, %24 ], [ 1, %2 ]
%9 = phi i32 [ %17, %24 ], [ 0, %2 ]
%10 = phi i8* [ %18, %24 ], [ null, %2 ]
br label %11
11: ; preds = %5, %31
%12 = phi i32* [ %7, %5 ], [ %33, %31 ]
%13 = phi i32 [ %8, %5 ], [ 0, %31 ]
%14 = phi i32 [ %9, %5 ], [ %17, %31 ]
%15 = phi i8* [ %10, %5 ], [ %18, %31 ]
br label %16
16: ; preds = %11, %22
%17 = phi i32 [ 1, %22 ], [ %14, %11 ]
%18 = phi i8* [ %23, %22 ], [ %15, %11 ]
%19 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %19, label %54 [
i32 -1, label %58
i32 104, label %20
i32 101, label %22
i32 102, label %24
i32 111, label %31
i32 63, label %38
]
20: ; preds = %16
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([439 x i8], [439 x i8]* @.str.1, i64 0, i64 0), i64 438, i64 1, i32* %12)
br label %123
22: ; preds = %16
%23 = load i8*, i8** @optarg
br label %16
24: ; preds = %16
%25 = load i8*, i8** @optarg
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %5
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
br label %123
31: ; preds = %16
%32 = load i8*, i8** @optarg
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %11
35: ; preds = %31
%36 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
br label %123
38: ; preds = %16
%39 = load i8, i8* @optopt
switch i8 %39, label %49 [
i8 101, label %40
i8 102, label %43
i8 111, label %46
]
40: ; preds = %38
%41 = load i32*, i32** @stderr
%42 = tail call i64 @fwrite(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i64 48, i64 1, i32* %41)
br label %52
43: ; preds = %38
%44 = load i32*, i32** @stderr
%45 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 14, i64 1, i32* %44)
br label %52
46: ; preds = %38
%47 = load i32*, i32** @stderr
%48 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i64 15, i64 1, i32* %47)
br label %52
49: ; preds = %38
%50 = load i32*, i32** @stderr
%51 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %50)
br label %52
52: ; preds = %43, %49, %46, %40
%53 = load i32, i32* @EXIT_FAILURE
br label %123
54: ; preds = %16
%55 = load i32*, i32** @stderr
%56 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i64 14, i64 1, i32* %55)
%57 = load i32, i32* @EXIT_FAILURE
br label %123
58: ; preds = %16
%59 = icmp eq i32 %17, 0
br i1 %59, label %86, label %60
60: ; preds = %58
%61 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %18)
%62 = tail call i32 @evaluate(i32* %12, i8* %18)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32*, i32** @stderr
%66 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i64 18, i64 1, i32* %65)
br label %67
67: ; preds = %64, %60
%68 = load i32, i32* @optind
%69 = icmp eq i32 %68, %0
br i1 %69, label %120, label %70
70: ; preds = %67
%71 = sext i32 %68 to i64
br label %72
72: ; preds = %70, %82
%73 = phi i64 [ %71, %70 ], [ %83, %82 ]
%74 = getelementptr inbounds i8*, i8** %1, i64 %73
%75 = load i8*, i8** %74
%76 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %75)
%77 = tail call i32 @evaluate(i32* %12, i8* %75)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %72
%80 = load i32*, i32** @stderr
%81 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i64 18, i64 1, i32* %80)
br label %82
82: ; preds = %79, %72
%83 = add nsw i64 %73, 1
%84 = trunc i64 %83 to i32
%85 = icmp eq i32 %84, %0
br i1 %85, label %120, label %72
86: ; preds = %58
%87 = icmp eq i32 %13, 0
br i1 %87, label %90, label %88
88: ; preds = %86
%89 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i64 14, i64 1, i32* %12)
br label %90
90: ; preds = %88, %86
%91 = load i32, i32* @optind
%92 = icmp eq i32 %91, %0
br i1 %92, label %95, label %93
93: ; preds = %90
%94 = tail call i64 @fwrite(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0), i64 47, i64 1, i32* %12)
br label %95
95: ; preds = %93, %90
%96 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
br label %97
97: ; preds = %111, %95
br i1 %87, label %100, label %98
98: ; preds = %97
%99 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i64 4, i64 1, i32* %12)
br label %100
100: ; preds = %98, %97
%101 = tail call i32 @memset(i8* %96, i32 0, i32 2048)
%102 = tail call i64 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8* %96)
%103 = load i64, i64* @EOF
%104 = icmp eq i64 %102, %103
br i1 %104, label %115, label %105
105: ; preds = %100
br i1 %87, label %106, label %108
106: ; preds = %105
%107 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* %96)
br label %108
108: ; preds = %106, %105
%109 = tail call i32 @evaluate(i32* %12, i8* %96)
%110 = icmp eq i32 %109, 0
br i1 %110, label %112, label %111
111: ; preds = %108, %112
br label %97
112: ; preds = %108
%113 = load i32*, i32** @stderr
%114 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i64 18, i64 1, i32* %113)
br label %111
115: ; preds = %100
br i1 %87, label %118, label %116
116: ; preds = %115
%117 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i64 5, i64 1, i32* %12)
br label %118
118: ; preds = %115, %116
%119 = tail call i32 @free(i8* %96)
br label %120
120: ; preds = %82, %67, %118
%121 = tail call i32 @fclose(i32* %6)
%122 = tail call i32 @fclose(i32* %12)
br label %123
123: ; preds = %120, %54, %52, %35, %28, %20
%124 = phi i32 [ %57, %54 ], [ %53, %52 ], [ %37, %35 ], [ %30, %28 ], [ 0, %20 ], [ 0, %120 ]
ret i32 %124
}