#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, i, j, remainder, iter = 0;
  printf("Enter two non-negative integers: ");
  scanf("%d %d", &a, &b);
  i = a;
  j = b;
  while (j > 0) {
    printf("Iteration %d: i: %3d, j: %3d\n", ++iter, i, j);
    remainder = i % j;
    i = j;
    j = remainder;
  }
  printf("GCD of %d and %d is %d\n\n", a, b, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a6 <main+0x86>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <main+0x44>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee6(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%r14d
mov    (%rsp),%edx
test   %edx,%edx
jle    119d <main+0x7d>
mov    $0x1,%ebx
lea    0xec7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %edx,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%eax
cltd
idiv   %ebp
add    $0x1,%ebx
mov    %ebp,%r14d
test   %edx,%edx
jg     1170 <main+0x50>
mov    0x4(%rsp),%r14d
mov    (%rsp),%edx
jmp    11a0 <main+0x80>
mov    %r14d,%ebp
lea    0xe9f(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter two non-negative integers: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [30 x i8] c"Iteration %d: i: %3d, j: %3d\0A\00"
@.str.3 = [25 x i8] c"GCD of %d and %d is %d\0A\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
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 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* %4
%11 = load i32, i32* %3
store i32 %11, i32* %5
br label %12
12: ; preds = %15, %0
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = srem i32 %21, %22
store i32 %23, i32* %6
%24 = load i32, i32* %5
store i32 %24, i32* %4
%25 = load i32, i32* %6
store i32 %25, i32* %5
br label %12
26: ; preds = %12
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter two non-negative integers: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [30 x i8] c"Iteration %d: i: %3d, j: %3d\0A\00"
@.str.3 = [25 x i8] c"GCD of %d and %d is %d\0A\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 ([34 x i8], [34 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
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %0, %10
%11 = phi i32 [ %14, %10 ], [ 0, %0 ]
%12 = phi i32 [ %13, %10 ], [ %7, %0 ]
%13 = phi i32 [ %16, %10 ], [ %8, %0 ]
%14 = add nuw nsw i32 %11, 1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %12, i32 %13)
%16 = srem i32 %12, %13
%17 = icmp sgt i32 %16, 0
br i1 %17, label %10, label %18
18: ; preds = %10
%19 = load i32, i32* %1
%20 = load i32, i32* %2
br label %21
21: ; preds = %18, %0
%22 = phi i32 [ %8, %0 ], [ %20, %18 ]
%23 = phi i32 [ %7, %0 ], [ %19, %18 ]
%24 = phi i32 [ %7, %0 ], [ %13, %18 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %22, i32 %24)
ret i32 0
}