#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ system(char *);
char *calc_expr(char *expr) {
  FILE *fp = fopen("conta.dat", "w+");
  fputs(expr, fp);
  fputs("\nquit", fp);
  fclose(fp);
  system("bc -l < conta.dat > resultado.dat");
  system("cat resultado.dat | tail -1 | tee resultado.dat 1>/dev/null");
  fp = fopen("resultado.dat", "r");
  char *res = malloc(50 * sizeof(char));
  fgets(res, 50, fp);
  int i;
  for (i = 0; i < 50; i++)
    if (res[i] == '\n')
      res[i] = '\0';
  fclose(fp);
  system("rm resultado.dat conta.dat");
  return res;
}


x86 assembly (clang, -O0):
<calc_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xf07(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe59(%rip),%rdi
call   1040 <system@plt>
lea    0xe6f(%rip),%rdi
call   1040 <system@plt>
lea    0xe55(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x32,%esi
call   1060 <fgets@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x32,-0x1c(%rbp)
jge    123d <calc_expr+0xdd>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    122a <calc_expr+0xca>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122f <calc_expr+0xcf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ff <calc_expr+0x9f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe1c(%rip),%rdi
call   1040 <system@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_expr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xf1c(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
lea    0xe84(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe69(%rip),%rdi
call   1040 <system@plt>
lea    0xe7f(%rip),%rdi
call   1040 <system@plt>
lea    0xe65(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x32,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
xor    %eax,%eax
movdqa 0xdf2(%rip),%xmm0
movdqa 0xdfa(%rip),%xmm1
jmp    122e <calc_expr+0xbe>
nopl   0x0(%rax,%rax,1)
add    $0x8,%rax
cmp    $0x30,%rax
je     12ee <calc_expr+0x17e>
movq   (%rbx,%rax,1),%xmm3
movdqa %xmm3,%xmm2
pcmpeqb %xmm0,%xmm2
movd   %xmm2,%ecx
test   $0x1,%cl
je     1248 <calc_expr+0xd8>
movb   $0x0,(%rbx,%rax,1)
movdqa %xmm2,%xmm4
pslld  $0x8,%xmm4
movd   %xmm4,%ecx
shr    $0x10,%ecx
test   $0x1,%cl
je     1262 <calc_expr+0xf2>
movb   $0x0,0x1(%rbx,%rax,1)
pshuflw $0x55,%xmm3,%xmm4
pcmpeqb %xmm0,%xmm4
pextrw $0x2,%xmm4,%ecx
test   $0x1,%cl
je     127a <calc_expr+0x10a>
movb   $0x0,0x2(%rbx,%rax,1)
movdqa %xmm2,%xmm4
psllq  $0x18,%xmm4
pextrw $0x3,%xmm4,%ecx
test   $0x1,%cl
je     1292 <calc_expr+0x122>
movb   $0x0,0x3(%rbx,%rax,1)
pshufd $0x55,%xmm3,%xmm3
pcmpeqb %xmm1,%xmm3
pextrw $0x4,%xmm3,%ecx
test   $0x1,%cl
je     12aa <calc_expr+0x13a>
movb   $0x0,0x4(%rbx,%rax,1)
movdqa %xmm2,%xmm3
pslldq $0x5,%xmm3
pextrw $0x5,%xmm3,%ecx
test   $0x1,%cl
je     12c2 <calc_expr+0x152>
movb   $0x0,0x5(%rbx,%rax,1)
pextrw $0x3,%xmm2,%ecx
test   $0x1,%cl
je     12d1 <calc_expr+0x161>
movb   $0x0,0x6(%rbx,%rax,1)
pslldq $0x7,%xmm2
pextrw $0x7,%xmm2,%ecx
test   $0x1,%cl
je     1220 <calc_expr+0xb0>
movb   $0x0,0x7(%rbx,%rax,1)
jmp    1220 <calc_expr+0xb0>
cmpb   $0xa,0x30(%rbx)
jne    12f8 <calc_expr+0x188>
movb   $0x0,0x30(%rbx)
cmpb   $0xa,0x31(%rbx)
jne    1302 <calc_expr+0x192>
movb   $0x0,0x31(%rbx)
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xd78(%rip),%rdi
call   1040 <system@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"conta.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"\0Aquit\00"
@.str.3 = [34 x i8] c"bc -l < conta.dat > resultado.dat\00"
@.str.4 = [60 x i8] c"cat resultado.dat | tail -1 | tee resultado.dat 1>/dev/null\00"
@.str.5 = [14 x i8] c"resultado.dat\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [27 x i8] c"rm resultado.dat conta.dat\00"
define i8* @calc_expr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i8*, i8** %2
%8 = load i32*, i32** %3
%9 = call i32 @fputs(i8* %7, i32* %8)
%10 = load i32*, i32** %3
%11 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %10)
%12 = load i32*, i32** %3
%13 = call i32 @fclose(i32* %12)
%14 = call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @system(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %16, i32** %3
%17 = call i8* @malloc(i32 50)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i32*, i32** %3
%20 = call i32 @fgets(i8* %18, i32 50, i32* %19)
store i32 0, i32* %5
br label %21
21: ; preds = %38, %1
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 50
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %32, %24
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %21
41: ; preds = %21
%42 = load i32*, i32** %3
%43 = call i32 @fclose(i32* %42)
%44 = call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [10 x i8] c"conta.dat\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [6 x i8] c"\0Aquit\00"
@.str.3 = [34 x i8] c"bc -l < conta.dat > resultado.dat\00"
@.str.4 = [60 x i8] c"cat resultado.dat | tail -1 | tee resultado.dat 1>/dev/null\00"
@.str.5 = [14 x i8] c"resultado.dat\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [27 x i8] c"rm resultado.dat conta.dat\00"
define i8* @calc_expr(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @fputs(i8* %0, i32* %2)
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5, i64 1, i32* %2)
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @system(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%9 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%10 = tail call i32 @fgets(i8* %9, i32 50, i32* %8)
br label %11
11: ; preds = %55, %1
%12 = phi i64 [ 0, %1 ], [ %56, %55 ]
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = bitcast i8* %13 to <8 x i8>*
%15 = load <8 x i8>, <8 x i8>* %14
%16 = icmp eq <8 x i8> %15, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%17 = extractelement <8 x i1> %16, i64 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = getelementptr inbounds i8, i8* %9, i64 %12
store i8 0, i8* %19
br label %20
20: ; preds = %18, %11
%21 = extractelement <8 x i1> %16, i64 1
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = or i64 %12, 1
%24 = getelementptr inbounds i8, i8* %9, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %22, %20
%26 = extractelement <8 x i1> %16, i64 2
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = or i64 %12, 2
%29 = getelementptr inbounds i8, i8* %9, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %27, %25
%31 = extractelement <8 x i1> %16, i64 3
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = or i64 %12, 3
%34 = getelementptr inbounds i8, i8* %9, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %32, %30
%36 = extractelement <8 x i1> %16, i64 4
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = or i64 %12, 4
%39 = getelementptr inbounds i8, i8* %9, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %37, %35
%41 = extractelement <8 x i1> %16, i64 5
br i1 %41, label %42, label %45
42: ; preds = %40
%43 = or i64 %12, 5
%44 = getelementptr inbounds i8, i8* %9, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %42, %40
%46 = extractelement <8 x i1> %16, i64 6
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = or i64 %12, 6
%49 = getelementptr inbounds i8, i8* %9, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %47, %45
%51 = extractelement <8 x i1> %16, i64 7
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = or i64 %12, 7
%54 = getelementptr inbounds i8, i8* %9, i64 %53
store i8 0, i8* %54
br label %55
55: ; preds = %52, %50
%56 = add nuw i64 %12, 8
%57 = icmp eq i64 %56, 48
br i1 %57, label %58, label %11
58: ; preds = %55
%59 = getelementptr inbounds i8, i8* %9, i64 48
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 10
br i1 %61, label %62, label %63
62: ; preds = %58
store i8 0, i8* %59
br label %63
63: ; preds = %58, %62
%64 = getelementptr inbounds i8, i8* %9, i64 49
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 10
br i1 %66, label %67, label %68
67: ; preds = %63
store i8 0, i8* %64
br label %68
68: ; preds = %67, %63
%69 = tail call i32 @fclose(i32* %8)
%70 = tail call i32 @system(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
ret i8* %9
}