#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 *, ...);
void extended_euclid(long a, long b, long *x, long *y, long *d) {
  long q, r, x1, x2, y1, y2;
  if (b == 0) {
    *d = a, *x = 1, *y = 0;
    return;
  }
  x2 = 1, x1 = 0, y2 = 0, y1 = 1;
  printf("------------------------------");
  printf("-------------------\n");
  printf("q    r    x    y    a    b    ");
  printf("x2   x1   y2   y1\n");
  printf("------------------------------");
  printf("-------------------\n");
  while (b > 0) {
    q = a / b, r = a - q * b;
    *x = x2 - q * x1, *y = y2 - q * y1;
    a = b, b = r;
    x2 = x1, x1 = *x, y2 = y1, y1 = *y;
    printf("%4ld %4ld %4ld %4ld ", q, r, *x, *y);
    printf("%4ld %4ld %4ld %4ld ", a, b, x2, x1);
    printf("%4ld %4ld\n", y2, y1);
  }
  *d = a, *x = x2, *y = y2;
  printf("------------------------------");
  printf("-------------------\n");
}


x86 assembly (clang, -O0):
<extended_euclid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <extended_euclid+0x4d>
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    12fc <extended_euclid+0x1ec>
movq   $0x1,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x1,-0x50(%rbp)
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jle    12bf <extended_euclid+0x1af>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%rax
imul   -0x40(%rbp),%rax
sub    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rcx
mov    -0x30(%rbp),%rax
imul   -0x50(%rbp),%rax
sub    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdx
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d1 <extended_euclid+0xc1>
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extended_euclid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
test   %rsi,%rsi
je     1276 <extended_euclid+0x156>
mov    %r8,0x18(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rcx,0x10(%rsp)
lea    0xeb0(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
mov    %rsi,%r15
call   1040 <printf@plt>
lea    0xea7(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
test   %r15,%r15
jle    1296 <extended_euclid+0x176>
mov    $0x1,%ecx
xor    %ebp,%ebp
xor    %r8d,%r8d
jmp    124d <extended_euclid+0x12d>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rax
cqto
idiv   %r15
mov    %rax,%rsi
mov    0x10(%rsp),%rbp
mov    0x8(%rsp),%rdi
mov    %rsi,%rax
imul   %r12,%rax
sub    %rax,%rcx
mov    %rcx,(%rdi)
mov    %rsi,%rax
imul   %r13,%rax
mov    %r8,%r14
sub    %rax,%r14
mov    %r14,0x0(%rbp)
mov    (%rdi),%rbp
lea    0xe41(%rip),%rbx
mov    %rbx,%rdi
mov    %rbp,%rcx
mov    %r14,%r8
xor    %eax,%eax
mov    %rdx,%r15
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe21(%rip),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdx
mov    %r13,%r8
mov    %r12,%rcx
test   %r15,%r15
jle    12a2 <extended_euclid+0x182>
mov    %rbp,%r12
mov    %r14,%r13
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
mov    %r15,0x20(%rsp)
jne    11c0 <extended_euclid+0xa0>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%esi
jmp    11cb <extended_euclid+0xab>
mov    %rbx,(%r8)
movq   $0x1,(%rdx)
movq   $0x0,(%rcx)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdx
mov    $0x1,%r12d
xor    %r13d,%r13d
mov    0x18(%rsp),%rax
mov    %rdx,(%rax)
mov    0x8(%rsp),%rax
mov    %r12,(%rax)
mov    0x10(%rsp),%rax
mov    %r13,(%rax)
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd3c(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"------------------------------\00"
@.str.1 = [21 x i8] c"-------------------\0A\00"
@.str.2 = [31 x i8] c"q r x y a b \00"
@.str.3 = [19 x i8] c"x2 x1 y2 y1\0A\00"
@.str.4 = [21 x i8] c"%4ld %4ld %4ld %4ld \00"
@.str.5 = [11 x i8] c"%4ld %4ld\0A\00"
define void @extended_euclid(i64 %0, i64 %1, i64* %2, i64* %3, i64* %4) {
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i64 %0, i64* %6
store i64 %1, i64* %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i64* %4, i64** %10
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %5
%20 = load i64, i64* %6
%21 = load i64*, i64** %10
store i64 %20, i64* %21
%22 = load i64*, i64** %8
store i64 1, i64* %22
%23 = load i64*, i64** %9
store i64 0, i64* %23
br label %87
24: ; preds = %5
store i64 1, i64* %14
store i64 0, i64* %13
store i64 0, i64* %16
store i64 1, i64* %15
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %34, %24
%32 = load i64, i64* %7
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %78
34: ; preds = %31
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = sdiv i64 %35, %36
store i64 %37, i64* %11
%38 = load i64, i64* %6
%39 = load i64, i64* %11
%40 = load i64, i64* %7
%41 = mul nsw i64 %39, %40
%42 = sub nsw i64 %38, %41
store i64 %42, i64* %12
%43 = load i64, i64* %14
%44 = load i64, i64* %11
%45 = load i64, i64* %13
%46 = mul nsw i64 %44, %45
%47 = sub nsw i64 %43, %46
%48 = load i64*, i64** %8
store i64 %47, i64* %48
%49 = load i64, i64* %16
%50 = load i64, i64* %11
%51 = load i64, i64* %15
%52 = mul nsw i64 %50, %51
%53 = sub nsw i64 %49, %52
%54 = load i64*, i64** %9
store i64 %53, i64* %54
%55 = load i64, i64* %7
store i64 %55, i64* %6
%56 = load i64, i64* %12
store i64 %56, i64* %7
%57 = load i64, i64* %13
store i64 %57, i64* %14
%58 = load i64*, i64** %8
%59 = load i64, i64* %58
store i64 %59, i64* %13
%60 = load i64, i64* %15
store i64 %60, i64* %16
%61 = load i64*, i64** %9
%62 = load i64, i64* %61
store i64 %62, i64* %15
%63 = load i64, i64* %11
%64 = load i64, i64* %12
%65 = load i64*, i64** %8
%66 = load i64, i64* %65
%67 = load i64*, i64** %9
%68 = load i64, i64* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %63, i64 %64, i64 %66, i64 %68)
%70 = load i64, i64* %6
%71 = load i64, i64* %7
%72 = load i64, i64* %14
%73 = load i64, i64* %13
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %70, i64 %71, i64 %72, i64 %73)
%75 = load i64, i64* %16
%76 = load i64, i64* %15
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 %75, i64 %76)
br label %31
78: ; preds = %31
%79 = load i64, i64* %6
%80 = load i64*, i64** %10
store i64 %79, i64* %80
%81 = load i64, i64* %14
%82 = load i64*, i64** %8
store i64 %81, i64* %82
%83 = load i64, i64* %16
%84 = load i64*, i64** %9
store i64 %83, i64* %84
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %87
87: ; preds = %78, %19
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"------------------------------\00"
@.str.2 = [31 x i8] c"q r x y a b \00"
@.str.4 = [21 x i8] c"%4ld %4ld %4ld %4ld \00"
@.str.5 = [11 x i8] c"%4ld %4ld\0A\00"
@str.6 = [18 x i8] c"x2 x1 y2 y1\00"
@str.8 = [20 x i8] c"-------------------\00"
define void @extended_euclid(i64 %0, i64 %1, i64* nocapture %2, i64* nocapture writeonly %3, i64* nocapture writeonly %4) {
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %8
7: ; preds = %5
store i64 %0, i64* %4
store i64 1, i64* %2
store i64 0, i64* %3
br label %41
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%15 = icmp sgt i64 %1, 0
br i1 %15, label %16, label %35
16: ; preds = %8, %16
%17 = phi i64 [ %18, %16 ], [ 0, %8 ]
%18 = phi i64 [ %29, %16 ], [ 1, %8 ]
%19 = phi i64 [ %20, %16 ], [ 1, %8 ]
%20 = phi i64 [ %30, %16 ], [ 0, %8 ]
%21 = phi i64 [ %22, %16 ], [ %0, %8 ]
%22 = phi i64 [ %25, %16 ], [ %1, %8 ]
%23 = sdiv i64 %21, %22
%24 = mul nsw i64 %23, %22
%25 = srem i64 %21, %22
%26 = mul nsw i64 %23, %20
%27 = sub nsw i64 %19, %26
store i64 %27, i64* %2
%28 = mul nsw i64 %23, %18
%29 = sub nsw i64 %17, %28
store i64 %29, i64* %3
%30 = load i64, i64* %2
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %23, i64 %25, i64 %30, i64 %29)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 %22, i64 %25, i64 %20, i64 %30)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 %18, i64 %29)
%34 = icmp sgt i64 %25, 0
br i1 %34, label %16, label %35
35: ; preds = %16, %8
%36 = phi i64 [ %0, %8 ], [ %22, %16 ]
%37 = phi i64 [ 1, %8 ], [ %20, %16 ]
%38 = phi i64 [ 0, %8 ], [ %18, %16 ]
store i64 %36, i64* %4
store i64 %37, i64* %2
store i64 %38, i64* %3
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
br label %41
41: ; preds = %35, %7
ret void
}