#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 */

/* Variables and functions */
int /*<<< orphan*/ div(int, int, int, int, int *, int *);
int euclides_mdc(int, int);
int /*<<< orphan*/ mult(int, int, int, int, int *, int *);
int /*<<< orphan*/ printf(char *, int, int, int, int, int);
int /*<<< orphan*/ scanf(char *, int *, int *, char *, int *, int *);
int /*<<< orphan*/ subtr(int, int, int, int, int *, int *);
int /*<<< orphan*/ sum(int, int, int, int, int *, int *);
void calc() {
  int n1, d1, n2, d2, r1, r2;
  char operator;
  scanf("%d / %d %c %d / %d", &n1, &d1, &operator, & n2, &d2);
  switch (operator) {
  case '+':
    sum(n1, d1, n2, d2, &r1, &r2);
    break;
  case '-':
    subtr(n1, d1, n2, d2, &r1, &r2);
    break;
  case '*':
    mult(n1, d1, n2, d2, &r1, &r2);
    break;
  case '/':
    div(n1, d1, n2, d2, &r1, &r2);
    break;
  }
  int mdc = euclides_mdc(r1, r2);
  printf("%d/%d = %d/%d\n", r1, r2, r1 / mdc, r2 / mdc, mdc);
}


x86 assembly (clang, -O0):
<calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe99(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    -0x19(%rbp),%rcx
lea    -0xc(%rbp),%r8
lea    -0x10(%rbp),%r9
call   1070 <scanf@plt>
movsbl -0x19(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1235 <calc+0xc5>
mov    -0x28(%rbp),%rax
lea    0xe47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1040 <sum@plt>
jmp    1235 <calc+0xc5>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1090 <subtr@plt>
jmp    1235 <calc+0xc5>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1050 <mult@plt>
jmp    1235 <calc+0xc5>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1060 <div@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1080 <euclides_mdc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    -0x2c(%rbp),%edx
mov    %eax,%r8d
mov    -0x20(%rbp),%r9d
lea    0xdbe(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc>:
sub    $0x28,%rsp
lea    0xe9d(%rip),%rdi
lea    0x24(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0xf(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x18(%rsp),%r9
call   1070 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     123c <calc+0xcc>
lea    0xe4f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x24(%rsp),%edi
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
call   1050 <mult@plt>
jmp    123c <calc+0xcc>
mov    0x24(%rsp),%edi
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
call   1040 <sum@plt>
jmp    123c <calc+0xcc>
mov    0x24(%rsp),%edi
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
call   1090 <subtr@plt>
jmp    123c <calc+0xcc>
mov    0x24(%rsp),%edi
mov    0x20(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
call   1060 <div@plt>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1080 <euclides_mdc@plt>
mov    %eax,%r9d
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%ecx
mov    %esi,%eax
cltd
idiv   %r9d
mov    %eax,%r8d
mov    %ecx,%eax
cltd
idiv   %r9d
lea    0xdc1(%rip),%rdi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %eax,%r8d
call   1030 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%d / %d %c %d / %d\00"
@.str.1 = [15 x i8] c"%d/%d = %d/%d\0A\00"
define void @calc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = call i32 @scanf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i8* %7, i32* %3, i32* %4)
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
switch i32 %11, label %36 [
i32 43, label %12
i32 45, label %18
i32 42, label %24
i32 47, label %30
]
12: ; preds = %0
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @sum(i32 %13, i32 %14, i32 %15, i32 %16, i32* %5, i32* %6)
br label %36
18: ; preds = %0
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @subtr(i32 %19, i32 %20, i32 %21, i32 %22, i32* %5, i32* %6)
br label %36
24: ; preds = %0
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = call i32 @mult(i32 %25, i32 %26, i32 %27, i32 %28, i32* %5, i32* %6)
br label %36
30: ; preds = %0
%31 = load i32, i32* %1
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = call i32 @div(i32 %31, i32 %32, i32 %33, i32 %34, i32* %5, i32* %6)
br label %36
36: ; preds = %0, %30, %24, %18, %12
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = call i32 @euclides_mdc(i32 %37, i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = load i32, i32* %5
%43 = load i32, i32* %8
%44 = sdiv i32 %42, %43
%45 = load i32, i32* %6
%46 = load i32, i32* %8
%47 = sdiv i32 %45, %46
%48 = load i32, i32* %8
%49 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41, i32 %44, i32 %47, i32 %48)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"%d / %d %c %d / %d\00"
@.str.1 = [15 x i8] c"%d/%d = %d/%d\0A\00"
define void @calc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = call i32 @scanf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i8* %7, i32* %3, i32* %4)
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
switch i32 %16, label %41 [
i32 43, label %17
i32 45, label %23
i32 42, label %29
i32 47, label %35
]
17: ; preds = %0
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = call i32 @sum(i32 %18, i32 %19, i32 %20, i32 %21, i32* %5, i32* %6)
br label %41
23: ; preds = %0
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @subtr(i32 %24, i32 %25, i32 %26, i32 %27, i32* %5, i32* %6)
br label %41
29: ; preds = %0
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 @mult(i32 %30, i32 %31, i32 %32, i32 %33, i32* %5, i32* %6)
br label %41
35: ; preds = %0
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = call i32 @div(i32 %36, i32 %37, i32 %38, i32 %39, i32* %5, i32* %6)
br label %41
41: ; preds = %0, %35, %29, %23, %17
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @euclides_mdc(i32 %42, i32 %43)
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = sdiv i32 %45, %44
%48 = sdiv i32 %46, %44
%49 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46, i32 %47, i32 %48, i32 %44)
ret void
}