#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 *);
int main(void) {
  int num, den, r;
  int m = 0;
  int n = 0;
  printf("Enter a fraction (x/y): ");
  scanf("%d/%d", &num, &den);
  m = den;
  n = num;
  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }
  num /= m;
  den /= m;
  printf("In lowest terms: %d/%d\n", num, den);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1190 <main+0x70>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    116b <main+0x4b>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%esi
mov    %ecx,%edi
test   %esi,%esi
je     116b <main+0x4b>
mov    %esi,%edx
mov    %ecx,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edx,%edi
cltd
idiv   %edi
mov    %edi,%eax
test   %edx,%edx
jne    1160 <main+0x40>
mov    %esi,%eax
cltd
idiv   %edi
mov    %eax,%esi
mov    %eax,0x4(%rsp)
mov    %ecx,%eax
cltd
idiv   %edi
mov    %eax,(%rsp)
lea    0xe9a(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Enter a fraction (x/y): \00"
@.str.1 = [6 x i8] c"%d/%d\00"
@.str.2 = [24 x i8] c"In lowest terms: %d/%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %3
store i32 %9, i32* %5
%10 = load i32, i32* %2
store i32 %10, i32* %6
br label %11
11: ; preds = %14, %0
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = srem i32 %15, %16
store i32 %17, i32* %4
%18 = load i32, i32* %6
store i32 %18, i32* %5
%19 = load i32, i32* %4
store i32 %19, i32* %6
br label %11
20: ; preds = %11
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = sdiv i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %5
%25 = load i32, i32* %3
%26 = sdiv i32 %25, %24
store i32 %26, i32* %3
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Enter a fraction (x/y): \00"
@.str.1 = [6 x i8] c"%d/%d\00"
@.str.2 = [24 x i8] c"In lowest terms: %d/%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %0, %10
%11 = phi i32 [ %13, %10 ], [ %8, %0 ]
%12 = phi i32 [ %11, %10 ], [ %7, %0 ]
%13 = srem i32 %12, %11
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %0
%16 = phi i32 [ %7, %0 ], [ %11, %10 ]
%17 = sdiv i32 %8, %16
store i32 %17, i32* %1
%18 = sdiv i32 %7, %16
store i32 %18, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
ret i32 0
}