#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 n, n2, m, d, remainder;
  printf("Enter a fraction: ");
  scanf("%1d / %d", &n, &d);
  m = n;
  n2 = n;
  while (n != 0) {
    remainder = m % n;
    m = n;
    n = remainder;
  }
  printf("In lowest terms: %d/%d\n", n2 / m, (d / m));
  return 0;
}


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    -0x14(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1182 <main+0x62>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    115d <main+0x3d>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%esi
mov    -0x14(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%edx
lea    0xe81(%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    0xedd(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1040 <scanf@plt>
mov    (%rsp),%ecx
test   %ecx,%ecx
je     1151 <main+0x31>
movl   $0x0,(%rsp)
mov    0x4(%rsp),%eax
cltd
idiv   %ecx
lea    0xebd(%rip),%rdi
mov    $0x1,%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 = [9 x i8] c"%1d / %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
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %5)
%9 = load i32, i32* %2
store i32 %9, i32* %4
%10 = load i32, i32* %2
store i32 %10, i32* %3
br label %11
11: ; preds = %14, %0
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = srem i32 %15, %16
store i32 %17, i32* %6
%18 = load i32, i32* %2
store i32 %18, i32* %4
%19 = load i32, i32* %6
store i32 %19, i32* %2
br label %11
20: ; preds = %11
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = sdiv i32 %21, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = sdiv i32 %24, %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter a fraction: \00"
@.str.1 = [9 x i8] c"%1d / %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 ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %0
store i32 0, i32* %1
br label %10
10: ; preds = %9, %0
%11 = load i32, i32* %2
%12 = sdiv i32 %11, %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %12)
ret i32 0
}