#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() {
  int numerator, denominator, reminder, gcd, orig_n, orig_d;
  printf("Enter a fraction: ");
  scanf("%d/%d", &numerator, &denominator);
  orig_n = numerator;
  orig_d = denominator;
  while (numerator >= 0) {
    reminder = numerator % denominator;
    denominator = numerator;
    numerator = reminder;
    if (numerator == 0) {
      gcd = denominator;
      break;
    }
  }
  printf("In lowest terms: %d/%d\n", orig_n / gcd, orig_d / gcd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1197 <main+0x77>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1192 <main+0x72>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x77>
jmp    115d <main+0x3d>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%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    0xedd(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%edi
mov    (%rsp),%r9d
mov    %r9d,%ecx
mov    %edi,%edx
mov    %edx,%esi
test   %edx,%edx
js     1168 <main+0x48>
mov    %esi,%eax
cltd
idiv   %ecx
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%ecx
test   %edx,%edx
jne    1150 <main+0x30>
mov    %edi,%eax
cltd
idiv   %esi
mov    %eax,%r8d
mov    %r9d,%eax
cltd
idiv   %esi
lea    0xe9c(%rip),%rdi
mov    %r8d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter a fraction: \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
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%10 = load i32, i32* %2
store i32 %10, i32* %6
%11 = load i32, i32* %3
store i32 %11, i32* %7
br label %12
12: ; preds = %25, %0
%13 = load i32, i32* %2
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = srem i32 %16, %17
store i32 %18, i32* %4
%19 = load i32, i32* %2
store i32 %19, i32* %3
%20 = load i32, i32* %4
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load i32, i32* %3
store i32 %24, i32* %5
br label %26
25: ; preds = %15
br label %12
26: ; preds = %23, %12
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = sdiv i32 %27, %28
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = sdiv i32 %30, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %32)
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter a fraction: \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 ([19 x i8], [19 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* %1
%8 = load i32, i32* %2
br label %9
9: ; preds = %13, %0
%10 = phi i32 [ %11, %13 ], [ %8, %0 ]
%11 = phi i32 [ %14, %13 ], [ %7, %0 ]
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = srem i32 %11, %10
store i32 %11, i32* %2
store i32 %14, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %13, %9
%17 = sdiv i32 %7, %11
%18 = sdiv i32 %8, %11
%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
}