#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned long rem;
};

/* Variables and functions */
TYPE_1__ ldiv(unsigned long, unsigned long);
unsigned long extended_gcd(unsigned long a, unsigned long b, int *u, int *v) {
  if (b == 0) {
    *u = 0;
    *v = 1;
    return a;
  }
  int u1, v1;
  unsigned long r = extended_gcd(b, ldiv(a, b).rem, &u1, &v1);
  *u = v1 - (a / b) * u1;
  *v = u1;
  return r;
}


x86 assembly (clang, -O0):
<extended_gcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1164 <extended_gcd+0x44>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d5 <extended_gcd+0xb5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ldiv@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <extended_gcd@plt>
mov    %rax,-0x38(%rbp)
movslq -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movslq -0x2c(%rbp),%rdx
imul   %rdx,%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extended_gcd>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
test   %rsi,%rsi
je     1170 <extended_gcd+0x50>
mov    %rsi,%rbx
mov    %r12,%rdi
call   1030 <ldiv@plt>
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <extended_gcd@plt>
mov    %rax,%rcx
mov    (%rsp),%esi
mov    %r12,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1180 <extended_gcd+0x60>
mov    %r12,%rax
xor    %edx,%edx
div    %rbx
jmp    1187 <extended_gcd+0x67>
movl   $0x0,(%r15)
movl   $0x1,(%r14)
jmp    1199 <extended_gcd+0x79>
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
mov    0x4(%rsp),%edx
imul   %edx,%eax
sub    %eax,%esi
mov    %esi,(%r15)
mov    %edx,(%r14)
mov    %rcx,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i64 }
define i64 @extended_gcd(i64 %0, i64 %1, i32* %2, i32* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca %struct.TYPE_2__
store i64 %0, i64* %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = load i64, i64* %7
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32*, i32** %8
store i32 0, i32* %17
%18 = load i32*, i32** %9
store i32 1, i32* %18
%19 = load i64, i64* %6
store i64 %19, i64* %5
br label %43
20: ; preds = %4
%21 = load i64, i64* %7
%22 = load i64, i64* %6
%23 = load i64, i64* %7
%24 = call i64 @ldiv(i64 %22, i64 %23)
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i64 %24, i64* %25
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
%27 = load i64, i64* %26
%28 = call i64 @extended_gcd(i64 %21, i64 %27, i32* %10, i32* %11)
store i64 %28, i64* %12
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = udiv i64 %31, %32
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = mul i64 %33, %35
%37 = sub i64 %30, %36
%38 = trunc i64 %37 to i32
%39 = load i32*, i32** %8
store i32 %38, i32* %39
%40 = load i32, i32* %10
%41 = load i32*, i32** %9
store i32 %40, i32* %41
%42 = load i64, i64* %12
store i64 %42, i64* %5
br label %43
43: ; preds = %20, %16
%44 = load i64, i64* %5
ret i64 %44
}

LLVM IR (-O2):
define i64 @extended_gcd(i64 %0, i64 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = alloca i32
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %9
8: ; preds = %4
store i32 0, i32* %2
store i32 1, i32* %3
br label %20
9: ; preds = %4
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = tail call i64 @ldiv(i64 %0, i64 %1)
%13 = call i64 @extended_gcd(i64 %1, i64 %12, i32* %5, i32* %6)
%14 = load i32, i32* %6
%15 = udiv i64 %0, %1
%16 = load i32, i32* %5
%17 = trunc i64 %15 to i32
%18 = mul i32 %16, %17
%19 = sub i32 %14, %18
store i32 %19, i32* %2
store i32 %16, i32* %3
br label %20
20: ; preds = %9, %8
%21 = phi i64 [ %0, %8 ], [ %13, %9 ]
ret i64 %21
}