#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 gcd(int, int);
int /*<<< orphan*/ printf(char *, int, int, int, ...);
int main() {
  int a = 240, b = 46;
  int s0 = 1, s1 = 0;
  int t0 = 0, t1 = 1;
  int r0 = a, r1 = b;
  printf("%dx+%dy=%d\n", a, b, gcd(a, b));
  int i = 0;
  while (1) {
    int q1 = r0 / r1;
    int r2 = r0 - q1 * r1;
    int s2 = s0 - q1 * s1;
    int t2 = t0 - q1 * t1;
    i++;
    printf("%d: %d,%d,%d,%d\n", i, q1, r2, s2, t2);
    r0 = r1, r1 = r2;
    s0 = s1, s1 = s2;
    t0 = t1, t1 = t2;
    if (r1 == 0) {
      printf("%d*%d+%d*%d=%d\n", a, s0, b, t0, r0);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf0,-0x8(%rbp)
movl   $0x2e,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <gcd@plt>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x24(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x2c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    124a <main+0x12a>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124f <main+0x12f>
jmp    1199 <main+0x79>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xf0,%r14d
mov    $0x2e,%ebp
mov    $0xf0,%edi
mov    $0x2e,%esi
call   1040 <gcd@plt>
lea    0xeb4(%rip),%rdi
mov    $0xf0,%esi
mov    $0x2e,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    $0x1,%ecx
xor    %r13d,%r13d
xor    %esi,%esi
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%r12d
mov    %r14d,%eax
cltd
idiv   %ebp
mov    %esi,0x4(%rsp)
mov    %r13d,%r14d
mov    %ecx,%r13d
mov    %eax,%ecx
imul   %esi,%ecx
sub    %ecx,%r15d
mov    %eax,%ecx
imul   %r13d,%ecx
sub    %ecx,%r14d
mov    %edx,%ebp
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
mov    %r14d,%ecx
mov    %r12d,%r14d
mov    %r15d,%esi
mov    0x4(%rsp),%r15d
test   %ebp,%ebp
jne    1180 <main+0x60>
lea    0xe41(%rip),%rdi
mov    $0xf0,%esi
mov    %r15d,%edx
mov    $0x2e,%ecx
mov    %r13d,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%dx+%dy=%d\0A\00"
@.str.1 = [17 x i8] c"%d: %d,%d,%d,%d\0A\00"
@.str.2 = [16 x i8] c"%d*%d+%d*%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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
store i32 240, i32* %2
store i32 46, i32* %3
store i32 1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 1, i32* %7
%15 = load i32, i32* %2
store i32 %15, i32* %8
%16 = load i32, i32* %3
store i32 %16, i32* %9
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = call i32 @gcd(i32 %19, i32 %20)
%22 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32 %21)
store i32 0, i32* %10
br label %23
23: ; preds = %0, %65
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = sdiv i32 %24, %25
store i32 %26, i32* %11
%27 = load i32, i32* %8
%28 = load i32, i32* %11
%29 = load i32, i32* %9
%30 = mul nsw i32 %28, %29
%31 = sub nsw i32 %27, %30
store i32 %31, i32* %12
%32 = load i32, i32* %4
%33 = load i32, i32* %11
%34 = load i32, i32* %5
%35 = mul nsw i32 %33, %34
%36 = sub nsw i32 %32, %35
store i32 %36, i32* %13
%37 = load i32, i32* %6
%38 = load i32, i32* %11
%39 = load i32, i32* %7
%40 = mul nsw i32 %38, %39
%41 = sub nsw i32 %37, %40
store i32 %41, i32* %14
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = load i32, i32* %14
%49 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45, i32 %46, i32 %47, i32 %48)
%50 = load i32, i32* %9
store i32 %50, i32* %8
%51 = load i32, i32* %12
store i32 %51, i32* %9
%52 = load i32, i32* %5
store i32 %52, i32* %4
%53 = load i32, i32* %13
store i32 %53, i32* %5
%54 = load i32, i32* %7
store i32 %54, i32* %6
%55 = load i32, i32* %14
store i32 %55, i32* %7
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %23
%59 = load i32, i32* %2
%60 = load i32, i32* %4
%61 = load i32, i32* %3
%62 = load i32, i32* %6
%63 = load i32, i32* %8
%64 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %59, i32 %60, i32 %61, i32 %62, i32 %63)
br label %66
65: ; preds = %23
br label %23
66: ; preds = %58
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"%dx+%dy=%d\0A\00"
@.str.1 = [17 x i8] c"%d: %d,%d,%d,%d\0A\00"
@.str.2 = [16 x i8] c"%d*%d+%d*%d=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @gcd(i32 240, i32 46)
%2 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 240, i32 46, i32 %1)
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 1, %0 ], [ %17, %3 ]
%5 = phi i32 [ 240, %0 ], [ %6, %3 ]
%6 = phi i32 [ 46, %0 ], [ %13, %3 ]
%7 = phi i32 [ 0, %0 ], [ %18, %3 ]
%8 = phi i32 [ 0, %0 ], [ %4, %3 ]
%9 = phi i32 [ 0, %0 ], [ %15, %3 ]
%10 = phi i32 [ 1, %0 ], [ %9, %3 ]
%11 = sdiv i32 %5, %6
%12 = mul nsw i32 %11, %6
%13 = srem i32 %5, %6
%14 = mul nsw i32 %11, %9
%15 = sub nsw i32 %10, %14
%16 = mul nsw i32 %11, %4
%17 = sub nsw i32 %8, %16
%18 = add nuw nsw i32 %7, 1
%19 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %11, i32 %13, i32 %15, i32 %17)
%20 = icmp eq i32 %13, 0
br i1 %20, label %21, label %3
21: ; preds = %3
%22 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 240, i32 %9, i32 46, i32 %4, i32 %6)
ret i32 0
}