#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *, char *, int *, int *);
int main(void) {
  int num1;
  int num2;
  int den1;
  int den2;
  int result_num;
  int result_den;
  char operator;
  printf("Enter 2 fractions (x/x (*, /, +, -) x/x): ");
  scanf("%d/%d %c %d/%d", &num1, &den1, &operator, & num2, &den2);
  switch (operator) {
  case '*':
    result_num = num1 * num2;
    result_den = den1 * den2;
    printf("The product is: %d/%d\n", result_num, result_den);
    break;
  case '/':
    result_num = num1 * den2;
    result_den = den1 * num2;
    printf("The quotient is: %d/%d\n", result_num, result_den);
    break;
  case '+':
    result_num = num1 * den2 + num2 * den1;
    result_den = den1 * den2;
    printf("The sum is: %d/%d\n", result_num, result_den);
    break;
  case '-':
    result_num = num1 * den2 - num2 * den1;
    result_den = den1 * den2;
    printf("The difference is: %d/%d\n", result_num, result_den);
    break;
  default:
    printf("Invalid input!");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeff(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x1d(%rbp),%rcx
lea    -0xc(%rbp),%r8
lea    -0x14(%rbp),%r9
call   1040 <scanf@plt>
movsbl -0x1d(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     124d <main+0x12d>
mov    -0x28(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125b <main+0x13b>
mov    -0x8(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125b <main+0x13b>
mov    -0x8(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125b <main+0x13b>
mov    -0x8(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125b <main+0x13b>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x7(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x8(%rsp),%r9
call   1040 <scanf@plt>
movsbl 0x7(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     11b3 <main+0x93>
lea    0xe95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x10(%rsp),%esi
imul   0x14(%rsp),%esi
mov    0x8(%rsp),%edx
imul   0xc(%rsp),%edx
lea    0xec5(%rip),%rdi
jmp    1200 <main+0xe0>
mov    0x8(%rsp),%eax
mov    0x14(%rsp),%ecx
imul   %eax,%ecx
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%esi
imul   %edx,%esi
add    %ecx,%esi
imul   %eax,%edx
lea    0xed0(%rip),%rdi
jmp    1200 <main+0xe0>
lea    0xef4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1207 <main+0xe7>
mov    0x8(%rsp),%eax
mov    0x14(%rsp),%esi
imul   %eax,%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
imul   %edx,%ecx
sub    %ecx,%esi
imul   %eax,%edx
lea    0xeaf(%rip),%rdi
jmp    1200 <main+0xe0>
mov    0x8(%rsp),%esi
imul   0x14(%rsp),%esi
mov    0x10(%rsp),%edx
imul   0xc(%rsp),%edx
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Enter 2 fractions (x/x (*, /, +, -) x/x): \00"
@.str.1 = [15 x i8] c"%d/%d %c %d/%d\00"
@.str.2 = [23 x i8] c"The product is: %d/%d\0A\00"
@.str.3 = [24 x i8] c"The quotient is: %d/%d\0A\00"
@.str.4 = [19 x i8] c"The sum is: %d/%d\0A\00"
@.str.5 = [26 x i8] c"The difference is: %d/%d\0A\00"
@.str.6 = [15 x i8] c"Invalid input!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %4, i8* %8, i32* %3, i32* %5)
%11 = load i8, i8* %8
%12 = sext i8 %11 to i32
switch i32 %12, label %61 [
i32 42, label %13
i32 47, label %23
i32 43, label %33
i32 45, label %47
]
13: ; preds = %0
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %6
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = mul nsw i32 %17, %18
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
br label %63
23: ; preds = %0
%24 = load i32, i32* %2
%25 = load i32, i32* %5
%26 = mul nsw i32 %24, %25
store i32 %26, i32* %6
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = mul nsw i32 %27, %28
store i32 %29, i32* %7
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31)
br label %63
33: ; preds = %0
%34 = load i32, i32* %2
%35 = load i32, i32* %5
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %3
%38 = load i32, i32* %4
%39 = mul nsw i32 %37, %38
%40 = add nsw i32 %36, %39
store i32 %40, i32* %6
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = mul nsw i32 %41, %42
store i32 %43, i32* %7
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %44, i32 %45)
br label %63
47: ; preds = %0
%48 = load i32, i32* %2
%49 = load i32, i32* %5
%50 = mul nsw i32 %48, %49
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = mul nsw i32 %51, %52
%54 = sub nsw i32 %50, %53
store i32 %54, i32* %6
%55 = load i32, i32* %4
%56 = load i32, i32* %5
%57 = mul nsw i32 %55, %56
store i32 %57, i32* %7
%58 = load i32, i32* %6
%59 = load i32, i32* %7
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %58, i32 %59)
br label %63
61: ; preds = %0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %47, %33, %23, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"Enter 2 fractions (x/x (*, /, +, -) x/x): \00"
@.str.1 = [15 x i8] c"%d/%d %c %d/%d\00"
@.str.2 = [23 x i8] c"The product is: %d/%d\0A\00"
@.str.3 = [24 x i8] c"The quotient is: %d/%d\0A\00"
@.str.4 = [19 x i8] c"The sum is: %d/%d\0A\00"
@.str.5 = [26 x i8] c"The difference is: %d/%d\0A\00"
@.str.6 = [15 x i8] c"Invalid input!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %3, i8* %5, i32* %2, i32* %4)
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
switch i32 %13, label %50 [
i32 42, label %14
i32 47, label %22
i32 43, label %30
i32 45, label %40
]
14: ; preds = %0
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, %15
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = mul nsw i32 %19, %18
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %20)
br label %52
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %4
%25 = mul nsw i32 %24, %23
%26 = load i32, i32* %3
%27 = load i32, i32* %2
%28 = mul nsw i32 %27, %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %28)
br label %52
30: ; preds = %0
%31 = load i32, i32* %1
%32 = load i32, i32* %4
%33 = mul nsw i32 %32, %31
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = mul nsw i32 %35, %34
%37 = add nsw i32 %36, %33
%38 = mul nsw i32 %35, %32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %38)
br label %52
40: ; preds = %0
%41 = load i32, i32* %1
%42 = load i32, i32* %4
%43 = mul nsw i32 %42, %41
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = mul nsw i32 %45, %44
%47 = sub nsw i32 %43, %46
%48 = mul nsw i32 %45, %42
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %47, i32 %48)
br label %52
50: ; preds = %0
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %40, %30, %22, %14
ret i32 0
}