#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, ...);
unsigned FindGCD(unsigned a, unsigned b, FILE *outputFile) {
  unsigned r;
  if (a < b) {
    r = a;
    a = b;
    b = r;
  }
  fprintf(outputFile, "%d &= %d * %d", a, b, a / b);
  r = a % b;
  if (r == 0) {
    fprintf(outputFile, " + %d\n", r);
    return (b);
  } else {
    fprintf(outputFile, " + %d\\\\\n", r);
    return (FindGCD(b, r, outputFile));
  }
}


x86 assembly (clang, -O0):
<FindGCD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1150 <FindGCD+0x30>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    -0x20(%rbp),%edx
mov    %eax,%r8d
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ae <FindGCD+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <FindGCD+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <FindGCD@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindGCD>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xeda(%rip),%r14
lea    0xee8(%rip),%r12
nopl   (%rax)
mov    %ebp,%ecx
cmp    %ebx,%ebp
mov    %ebx,%ebp
cmovb  %ecx,%ebp
cmovb  %ebx,%ecx
mov    %ecx,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ecx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %ebx,%ebx
je     116d <FindGCD+0x5d>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1130 <FindGCD+0x20>
lea    0xe9a(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"%d &= %d * %d\00"
@.str.1 = [7 x i8] c" + %d\0A\00"
@.str.2 = [9 x i8] c" + %d\\\\\0A\00"
define i32 @FindGCD(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* %5
store i32 %13, i32* %8
%14 = load i32, i32* %6
store i32 %14, i32* %5
%15 = load i32, i32* %8
store i32 %15, i32* %6
br label %16
16: ; preds = %12, %3
%17 = load i32*, i32** %7
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = udiv i32 %20, %21
%23 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %22)
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = urem i32 %24, %25
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %16
%30 = load i32*, i32** %7
%31 = load i32, i32* %8
%32 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %6
store i32 %33, i32* %4
br label %42
34: ; preds = %16
%35 = load i32*, i32** %7
%36 = load i32, i32* %8
%37 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %6
%39 = load i32, i32* %8
%40 = load i32*, i32** %7
%41 = call i32 @FindGCD(i32 %38, i32 %39, i32* %40)
store i32 %41, i32* %4
br label %42
42: ; preds = %34, %29
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [14 x i8] c"%d &= %d * %d\00"
@.str.1 = [7 x i8] c" + %d\0A\00"
@.str.2 = [9 x i8] c" + %d\\\\\0A\00"
define i32 @FindGCD(i32 %0, i32 %1, i32* nocapture %2) {
br label %4
4: ; preds = %16, %3
%5 = phi i32 [ %0, %3 ], [ %9, %16 ]
%6 = phi i32 [ %1, %3 ], [ %12, %16 ]
%7 = icmp ult i32 %5, %6
%8 = select i1 %7, i32 %6, i32 %5
%9 = select i1 %7, i32 %5, i32 %6
%10 = udiv i32 %8, %9
%11 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9, i32 %10)
%12 = urem i32 %8, %9
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 0)
ret i32 %9
16: ; preds = %4
%17 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %4
}