#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 a, b, remainder, denominator, numerator;
  printf("enter the fraction (numer/denom): ");
  scanf("%d/%d", &numerator, &denominator);
  a = numerator;
  b = denominator;
  if (a > b) {
    int temp = b;
    b = a;
    a = temp;
  }
  do {
    remainder = b % a;
    b = a;
    a = remainder;
  } while (remainder != 0);
  int gcd = b;
  printf("gcd is %d\n", gcd);
  numerator /= gcd;
  denominator /= gcd;
  printf("In lowest term: %d/%d\n", numerator, denominator);
  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    0xedf(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    117b <main+0x5b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <main+0x60>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1180 <main+0x60>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <scanf@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
cmp    %ecx,%edx
mov    %ecx,%eax
cmovg  %edx,%eax
cmovg  %ecx,%edx
nopl   0x0(%rax,%rax,1)
mov    %edx,%ebx
cltd
idiv   %ebx
mov    %ebx,%eax
test   %edx,%edx
jne    1160 <main+0x40>
lea    0xeb7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
cltd
idiv   %ebx
mov    %eax,%esi
mov    %eax,0x8(%rsp)
mov    0xc(%rsp),%eax
cltd
idiv   %ebx
mov    %eax,0xc(%rsp)
lea    0xe9a(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"enter the fraction (numer/denom): \00"
@.str.1 = [6 x i8] c"%d/%d\00"
@.str.2 = [11 x i8] c"gcd is %d\0A\00"
@.str.3 = [23 x i8] c"In lowest term: %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
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %5)
%11 = load i32, i32* %6
store i32 %11, i32* %2
%12 = load i32, i32* %5
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = load i32, i32* %3
store i32 %17, i32* %7
%18 = load i32, i32* %2
store i32 %18, i32* %3
%19 = load i32, i32* %7
store i32 %19, i32* %2
br label %20
20: ; preds = %16, %0
br label %21
21: ; preds = %27, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = srem i32 %22, %23
store i32 %24, i32* %4
%25 = load i32, i32* %2
store i32 %25, i32* %3
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %21
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %21, label %30
30: ; preds = %27
%31 = load i32, i32* %3
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = sdiv i32 %35, %34
store i32 %36, i32* %6
%37 = load i32, i32* %8
%38 = load i32, i32* %5
%39 = sdiv i32 %38, %37
store i32 %39, i32* %5
%40 = load i32, i32* %6
%41 = load i32, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"enter the fraction (numer/denom): \00"
@.str.1 = [6 x i8] c"%d/%d\00"
@.str.2 = [11 x i8] c"gcd is %d\0A\00"
@.str.3 = [23 x i8] c"In lowest term: %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 ([35 x i8], [35 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* %2, i32* %1)
%7 = load i32, i32* %2
%8 = load i32, i32* %1
%9 = icmp sgt i32 %7, %8
%10 = select i1 %9, i32 %7, i32 %8
%11 = select i1 %9, i32 %8, i32 %7
br label %12
12: ; preds = %12, %0
%13 = phi i32 [ %10, %0 ], [ %14, %12 ]
%14 = phi i32 [ %11, %0 ], [ %15, %12 ]
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%19 = load i32, i32* %2
%20 = sdiv i32 %19, %14
store i32 %20, i32* %2
%21 = load i32, i32* %1
%22 = sdiv i32 %21, %14
store i32 %22, i32* %1
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22)
ret i32 0
}