#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 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;
    }
  }
  printf("%d/%d=", a, b);
  int s = s1;
  int t = t1;
  if (s == 0)
    printf("Division by zero\n");
  else if (s == 1)
    printf("%d\n", -t);
  else if (s > 0)
    printf("%d/%d\n", -t, s);
  else
    printf("%d/%d\n", t, -s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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,-0x48(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <gcd@plt>
mov    -0x48(%rbp),%esi
mov    -0x44(%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>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    128c <main+0x16c>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f3 <main+0x1d3>
cmpl   $0x1,-0x3c(%rbp)
jne    12ae <main+0x18e>
xor    %esi,%esi
sub    -0x40(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1ce>
cmpl   $0x0,-0x3c(%rbp)
jle    12d3 <main+0x1b3>
xor    %esi,%esi
sub    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e9 <main+0x1c9>
mov    -0x40(%rbp),%esi
xor    %edx,%edx
sub    -0x3c(%rbp),%edx
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ee <main+0x1ce>
jmp    12f3 <main+0x1d3>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0xf0,0x4(%rsp)
mov    $0x2e,%r12d
mov    $0xf0,%edi
mov    $0x2e,%esi
call   1050 <gcd@plt>
lea    0xea1(%rip),%rdi
mov    $0xf0,%esi
mov    $0x2e,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    $0x1,%ebx
xor    %r15d,%r15d
xor    %ebp,%ebp
mov    $0x1,%r13d
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
cltd
mov    %r12d,0x4(%rsp)
idiv   %r12d
mov    %r13d,%ecx
mov    %ebp,%r13d
mov    %r15d,%esi
mov    %ebx,%r15d
mov    %eax,%edi
imul   %ebp,%edi
mov    %ecx,%ebp
sub    %edi,%ebp
mov    %eax,%ecx
imul   %ebx,%ecx
mov    %esi,%ebx
sub    %ecx,%ebx
mov    %edx,%r12d
lea    0xe47(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
test   %r12d,%r12d
jne    1190 <main+0x60>
lea    0xe33(%rip),%rdi
mov    $0xf0,%esi
mov    %r13d,%edx
mov    $0x2e,%ecx
mov    %r15d,%r8d
mov    0x4(%rsp),%r9d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0xf0,%esi
mov    $0x2e,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebp
je     1235 <main+0x105>
test   %ebp,%ebp
jne    1249 <main+0x119>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
jmp    1263 <main+0x133>
neg    %ebx
lea    0xddb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1263 <main+0x133>
jle    124f <main+0x11f>
neg    %ebx
jmp    1251 <main+0x121>
neg    %ebp
lea    0xddc(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <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"
@.str.3 = [7 x i8] c"%d/%d=\00"
@.str.4 = [18 x i8] c"Division by zero\0A\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [7 x i8] c"%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
%15 = alloca i32
%16 = 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
%17 = load i32, i32* %2
store i32 %17, i32* %8
%18 = load i32, i32* %3
store i32 %18, i32* %9
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @gcd(i32 %21, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i32 %23)
store i32 0, i32* %10
br label %25
25: ; preds = %0, %67
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = sdiv i32 %26, %27
store i32 %28, i32* %11
%29 = load i32, i32* %8
%30 = load i32, i32* %11
%31 = load i32, i32* %9
%32 = mul nsw i32 %30, %31
%33 = sub nsw i32 %29, %32
store i32 %33, i32* %12
%34 = load i32, i32* %4
%35 = load i32, i32* %11
%36 = load i32, i32* %5
%37 = mul nsw i32 %35, %36
%38 = sub nsw i32 %34, %37
store i32 %38, i32* %13
%39 = load i32, i32* %6
%40 = load i32, i32* %11
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
%43 = sub nsw i32 %39, %42
store i32 %43, i32* %14
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = load i32, i32* %13
%50 = load i32, i32* %14
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47, i32 %48, i32 %49, i32 %50)
%52 = load i32, i32* %9
store i32 %52, i32* %8
%53 = load i32, i32* %12
store i32 %53, i32* %9
%54 = load i32, i32* %5
store i32 %54, i32* %4
%55 = load i32, i32* %13
store i32 %55, i32* %5
%56 = load i32, i32* %7
store i32 %56, i32* %6
%57 = load i32, i32* %14
store i32 %57, i32* %7
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %25
%61 = load i32, i32* %2
%62 = load i32, i32* %4
%63 = load i32, i32* %3
%64 = load i32, i32* %6
%65 = load i32, i32* %8
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %61, i32 %62, i32 %63, i32 %64, i32 %65)
br label %68
67: ; preds = %25
br label %25
68: ; preds = %60
%69 = load i32, i32* %2
%70 = load i32, i32* %3
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %69, i32 %70)
%72 = load i32, i32* %5
store i32 %72, i32* %15
%73 = load i32, i32* %7
store i32 %73, i32* %16
%74 = load i32, i32* %15
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %68
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %100
78: ; preds = %68
%79 = load i32, i32* %15
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = load i32, i32* %16
%83 = sub nsw i32 0, %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %83)
br label %99
85: ; preds = %78
%86 = load i32, i32* %15
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %85
%89 = load i32, i32* %16
%90 = sub nsw i32 0, %89
%91 = load i32, i32* %15
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %90, i32 %91)
br label %98
93: ; preds = %85
%94 = load i32, i32* %16
%95 = load i32, i32* %15
%96 = sub nsw i32 0, %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %94, i32 %96)
br label %98
98: ; preds = %93, %88
br label %99
99: ; preds = %98, %81
br label %100
100: ; preds = %99, %76
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"
@.str.3 = [7 x i8] c"%d/%d=\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [7 x i8] c"%d/%d\0A\00"
@str = [17 x i8] c"Division by zero\00"
define i32 @main() {
%1 = tail call i32 @gcd(i32 240, i32 46)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) 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 [ 46, %0 ], [ %13, %3 ]
%5 = phi i32 [ 0, %0 ], [ %18, %3 ]
%6 = phi i32 [ 240, %0 ], [ %4, %3 ]
%7 = phi i32 [ 1, %0 ], [ %17, %3 ]
%8 = phi i32 [ 0, %0 ], [ %7, %3 ]
%9 = phi i32 [ 0, %0 ], [ %15, %3 ]
%10 = phi i32 [ 1, %0 ], [ %9, %3 ]
%11 = sdiv i32 %6, %4
%12 = mul nsw i32 %11, %4
%13 = srem i32 %6, %4
%14 = mul nsw i32 %11, %9
%15 = sub nsw i32 %10, %14
%16 = mul nsw i32 %11, %7
%17 = sub nsw i32 %8, %16
%18 = add nuw nsw i32 %5, 1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) 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*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 240, i32 %9, i32 46, i32 %7, i32 %4)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 240, i32 46)
switch i32 %15, label %29 [
i32 0, label %24
i32 1, label %26
]
24: ; preds = %21
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %37
26: ; preds = %21
%27 = sub nsw i32 0, %17
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %37
29: ; preds = %21
%30 = icmp sgt i32 %15, 0
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = sub nsw i32 0, %17
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %32, i32 %15)
br label %37
34: ; preds = %29
%35 = sub nsw i32 0, %15
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %17, i32 %35)
br label %37
37: ; preds = %26, %34, %31, %24
ret i32 0
}