#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 BUFSIZ;
scalar_t__ EOF;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int, int, char);
int printf(char *, ...);
int sscanf(char *, char *, int *, char *, int *);
int /*<<< orphan*/ stdin;
void be_bc(int todc[2], int fromdc[2]) {
  int num1, num2;
  char operation[BUFSIZ], message[BUFSIZ], *fgets();
  FILE *fpout, *fpin, *fdopen();
  close(todc[0]);
  close(fromdc[1]);
  fpout = fdopen(todc[1], "w");
  fpin = fdopen(fromdc[0], "r");
  if (fpout == NULL || fpin == NULL)
    fatal("Error convering pipes to streams");
  while (printf("tinybc: "), fgets(message, BUFSIZ, stdin) != NULL) {
    if (sscanf(message, "%d%[- + * / ^]%d", &num1, operation, &num2) != 3) {
      printf("syntax error\n");
      continue;
    }
    if (fprintf(fpout, "%d\n%d\n%c\np\n", num1, num2, *operation) == EOF)
      fatal("Error writing");
    fflush(fpout);
    if (fgets(message, BUFSIZ, fpin) == NULL)
      break;
    printf("%d %c %d = %s", num1, *operation, num2, message);
  }
  fclose(fpout);
  fclose(fpin);
}


x86 assembly (clang, -O0):
<be_bc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fdopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   10a0 <fdopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1248 <be_bc+0xb8>
cmpq   $0x0,-0x40(%rbp)
jne    1254 <be_bc+0xc4>
lea    0xdb5(%rip),%rdi
call   10b0 <fatal@plt>
jmp    1259 <be_bc+0xc9>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1354 <be_bc+0x1c4>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rdi
lea    0xd91(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%r8
call   1090 <sscanf@plt>
cmp    $0x3,%eax
je     12c6 <be_bc+0x136>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1259 <be_bc+0xc9>
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd72(%rip),%rsi
movsbl (%rax),%r8d
call   1070 <fprintf@plt>
mov    0x2cf5(%rip),%rcx
cmp    (%rcx),%rax
jne    1300 <be_bc+0x170>
lea    0xd5e(%rip),%rdi
call   10b0 <fatal@plt>
mov    -0x38(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x48(%rbp),%rdi
mov    0x2cbc(%rip),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
mov    $0x0,%al
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1330 <be_bc+0x1a0>
jmp    1354 <be_bc+0x1c4>
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%rax
mov    -0x14(%rbp),%esi
movsbl (%rax),%edx
mov    -0x18(%rbp),%ecx
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1259 <be_bc+0xc9>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<be_bc>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsp,-0x40(%rbp)
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%rcx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rdi),%edi
call   1060 <close@plt>
mov    0x4(%r12),%edi
call   1060 <close@plt>
mov    0x4(%r15),%edi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
call   10b0 <fdopen@plt>
mov    %rax,%r15
mov    (%r12),%edi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   10b0 <fdopen@plt>
mov    %rax,-0x38(%rbp)
test   %r15,%r15
je     1230 <be_bc+0x90>
cmpq   $0x0,-0x38(%rbp)
jne    123c <be_bc+0x9c>
lea    0xdcb(%rip),%rdi
call   10c0 <fatal@plt>
lea    0xde0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fgets@plt>
test   %rax,%rax
je     134e <be_bc+0x1ae>
lea    -0x2c(%rbp),%r13
lea    0xda9(%rip),%r12
jmp    12bb <be_bc+0x11b>
nopl   0x0(%rax)
lea    0xdde(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fgets@plt>
test   %rax,%rax
je     134e <be_bc+0x1ae>
mov    %rbx,%rdi
lea    0xd67(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    %r14,%rcx
mov    %r13,%r8
call   10a0 <sscanf@plt>
cmp    $0x3,%eax
jne    1280 <be_bc+0xe0>
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
movsbl (%r14),%r8d
mov    %r15,%rdi
lea    0xd50(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2ce7(%rip),%rcx
cmp    (%rcx),%rax
jne    130a <be_bc+0x16a>
lea    0xd44(%rip),%rdi
call   10c0 <fatal@plt>
mov    %r15,%rdi
call   1090 <fflush@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1070 <fgets@plt>
test   %rax,%rax
je     134e <be_bc+0x1ae>
mov    -0x30(%rbp),%esi
movsbl (%r14),%edx
mov    -0x2c(%rbp),%ecx
lea    0xd18(%rip),%rdi
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <printf@plt>
jmp    128c <be_bc+0xec>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Error convering pipes to streams\00"
@.str.3 = [9 x i8] c"tinybc: \00"
@stdin = global i32 0
@.str.4 = [17 x i8] c"%d%[- + * / ^]%d\00"
@.str.5 = [14 x i8] c"syntax error\0A\00"
@.str.6 = [12 x i8] c"%d\0A%d\0A%c\0Ap\0A\00"
@EOF = global i64 0
@.str.7 = [14 x i8] c"Error writing\00"
@.str.8 = [14 x i8] c"%d %c %d = %s\00"
define void @be_bc(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
store i64 %17, i64* %9
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 1
%29 = load i32, i32* %28
%30 = call i32* (i32, i8*, ...) bitcast (i32* (...)* @fdopen to i32* (i32, i8*, ...)*)(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %10
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 0
%33 = load i32, i32* %32
%34 = call i32* (i32, i8*, ...) bitcast (i32* (...)* @fdopen to i32* (i32, i8*, ...)*)(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %11
%35 = load i32*, i32** %10
%36 = icmp eq i32* %35, null
br i1 %36, label %40, label %37
37: ; preds = %2
%38 = load i32*, i32** %11
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %42
40: ; preds = %37, %2
%41 = call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
br label %43
43: ; preds = %72, %52, %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* @BUFSIZ
%46 = load i32, i32* @stdin
%47 = call i8* (i8*, i32, i32, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32, ...)*)(i8* %18, i32 %45, i32 %46)
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %78
49: ; preds = %43
%50 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32* %5, i8* %15, i32* %6)
%51 = icmp ne i32 %50, 3
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %43
54: ; preds = %49
%55 = load i32*, i32** %10
%56 = load i32, i32* %5
%57 = load i32, i32* %6
%58 = load i8, i8* %15
%59 = call i64 @fprintf(i32* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %56, i32 %57, i8 signext %58)
%60 = load i64, i64* @EOF
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %54
%63 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
%65 = load i32*, i32** %10
%66 = call i32 @fflush(i32* %65)
%67 = load i32, i32* @BUFSIZ
%68 = load i32*, i32** %11
%69 = call i8* (i8*, i32, i32*, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32*, ...)*)(i8* %18, i32 %67, i32* %68)
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %72
71: ; preds = %64
br label %78
72: ; preds = %64
%73 = load i32, i32* %5
%74 = load i8, i8* %15
%75 = sext i8 %74 to i32
%76 = load i32, i32* %6
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %73, i32 %75, i32 %76, i8* %18)
br label %43
78: ; preds = %71, %43
%79 = load i32*, i32** %10
%80 = call i32 @fclose(i32* %79)
%81 = load i32*, i32** %11
%82 = call i32 @fclose(i32* %81)
%83 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Error convering pipes to streams\00"
@.str.3 = [9 x i8] c"tinybc: \00"
@stdin = global i32 0
@.str.4 = [17 x i8] c"%d%[- + * / ^]%d\00"
@.str.6 = [12 x i8] c"%d\0A%d\0A%c\0Ap\0A\00"
@EOF = global i64 0
@.str.7 = [14 x i8] c"Error writing\00"
@.str.8 = [14 x i8] c"%d %c %d = %s\00"
@str = [13 x i8] c"syntax error\00"
define void @be_bc(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = load i32, i32* %0
%15 = tail call i32 @close(i32 %14)
%16 = getelementptr inbounds i32, i32* %1, i64 1
%17 = load i32, i32* %16
%18 = tail call i32 @close(i32 %17)
%19 = getelementptr inbounds i32, i32* %0, i64 1
%20 = load i32, i32* %19
%21 = tail call i32* (i32, i8*, ...) bitcast (i32* (...)* @fdopen to i32* (i32, i8*, ...)*)(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %1
%23 = tail call i32* (i32, i8*, ...) bitcast (i32* (...)* @fdopen to i32* (i32, i8*, ...)*)(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %21, null
%25 = icmp eq i32* %23, null
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = tail call i32 @fatal(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %2, %27
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @BUFSIZ
%32 = load i32, i32* @stdin
%33 = call i8* (i8*, i32, i32, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32, ...)*)(i8* %13, i32 %31, i32 %32)
%34 = icmp eq i8* %33, null
br i1 %34, label %66, label %35
35: ; preds = %29, %40
%36 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32* %3, i8* %10, i32* %4)
%37 = icmp eq i32 %36, 3
br i1 %37, label %46, label %38
38: ; preds = %35
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %60
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @BUFSIZ
%43 = load i32, i32* @stdin
%44 = call i8* (i8*, i32, i32, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32, ...)*)(i8* %13, i32 %42, i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %66, label %35
46: ; preds = %35
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = load i8, i8* %10
%50 = call i64 @fprintf(i32* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %47, i32 %48, i8 signext %49)
%51 = load i64, i64* @EOF
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %53, %46
%56 = call i32 @fflush(i32* %21)
%57 = load i32, i32* @BUFSIZ
%58 = call i8* (i8*, i32, i32*, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32*, ...)*)(i8* %13, i32 %57, i32* %23)
%59 = icmp eq i8* %58, null
br i1 %59, label %66, label %60
60: ; preds = %55
%61 = load i32, i32* %3
%62 = load i8, i8* %10
%63 = sext i8 %62 to i32
%64 = load i32, i32* %4
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %61, i32 %63, i32 %64, i8* %13)
br label %40
66: ; preds = %40, %55, %29
%67 = call i32 @fclose(i32* %21)
%68 = call i32 @fclose(i32* %23)
ret void
}