#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 n, m, reminder;
  printf("Enter two numbers: ");
  scanf("%d %d", &n, &m);
  if (n == 0) {
    printf("Greatest common divisor: %d\n", m);
    return 0;
  }
  if (m == 0) {
    printf("Greatest common divisor: %d\n", n);
    return 0;
  }
  while (n >= 0) {
    reminder = m % n;
    m = n;
    n = reminder;
    if (n == 0) {
      printf("Greatest common divisor: %d\n", m);
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1178 <main+0x58>
mov    -0xc(%rbp),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <main+0xd7>
cmpl   $0x0,-0xc(%rbp)
jne    119f <main+0x7f>
mov    -0x8(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <main+0xd7>
jmp    11a4 <main+0x84>
cmpl   $0x0,-0x8(%rbp)
jl     11f0 <main+0xd0>
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,-0x8(%rbp)
jne    11eb <main+0xcb>
mov    -0xc(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <main+0xd7>
jmp    11a4 <main+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%edx
mov    (%rsp),%eax
test   %edx,%edx
je     1178 <main+0x58>
test   %eax,%eax
je     117c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %edx,%edx
js     118c <main+0x6c>
mov    %edx,%esi
cltd
idiv   %esi
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%eax
test   %edx,%edx
jne    1160 <main+0x40>
jmp    117e <main+0x5e>
mov    %eax,%esi
jmp    117e <main+0x5e>
mov    %edx,%esi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"Enter two numbers: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [29 x i8] c"Greatest common divisor: %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 ([20 x i8], [20 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 = icmp eq i32 %7, 0
%9 = load i32, i32* %2
br i1 %8, label %19, label %10
10: ; preds = %0
%11 = icmp eq i32 %9, 0
br i1 %11, label %19, label %12
12: ; preds = %10, %16
%13 = phi i32 [ %14, %16 ], [ %9, %10 ]
%14 = phi i32 [ %17, %16 ], [ %7, %10 ]
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = srem i32 %13, %14
store i32 %14, i32* %2
store i32 %17, i32* %1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %12
19: ; preds = %16, %10, %0
%20 = phi i32 [ %9, %0 ], [ %7, %10 ], [ %14, %16 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %12, %19
ret i32 0
}