#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 j;
typedef int int64_t;
typedef int i;

/* Variables and functions */
int UINT32_C(int);
int div_euclid(int, int, int, int *);
int64_t scale_euclid(int64_t i, int64_t j, int64_t k, int64_t *q) {
  return div_euclid((((i) >> 32) * ((j) >> 32) +
                     (((((i) >> 32) * ((j)&UINT32_C(-1)) +
                        ((((i)&UINT32_C(-1)) * ((j)&UINT32_C(-1))) >> 32))) >>
                      32) +
                     ((((i)&UINT32_C(-1)) * ((j) >> 32) +
                       (((((i) >> 32) * ((j)&UINT32_C(-1)) +
                          ((((i)&UINT32_C(-1)) * ((j)&UINT32_C(-1))) >> 32))) &
                        UINT32_C(-1))) >>
                      32)),
                    i * j, k, q);
}


x86 assembly (clang, -O0):
<scale_euclid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    -0x8(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    -0x5c(%rbp),%ecx
mov    %eax,%edx
mov    -0x58(%rbp),%eax
and    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    -0x50(%rbp),%ecx
mov    -0x4c(%rbp),%esi
mov    -0x48(%rbp),%edx
mov    %eax,%edi
mov    -0x44(%rbp),%eax
and    %edi,%ecx
imul   %ecx,%esi
mov    $0x20,%ecx
sar    %cl,%esi
mov    %esi,%ecx
add    %ecx,%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
and    %ecx,%eax
mov    -0x8(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    -0x3c(%rbp),%ecx
mov    %eax,%edx
mov    -0x38(%rbp),%eax
and    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    -0x30(%rbp),%ecx
mov    -0x2c(%rbp),%edx
mov    %eax,%esi
mov    -0x28(%rbp),%eax
and    %esi,%ecx
imul   %ecx,%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%edi
mov    %eax,%edx
mov    -0x1c(%rbp),%eax
and    %edx,%ecx
add    %ecx,%eax
mov    $0x20,%ecx
sar    %cl,%eax
add    %eax,%edi
mov    -0x4(%rbp),%esi
imul   -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <div_euclid@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_euclid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
mov    $0xffffffff,%edi
call   1040 <UINT32_C@plt>
imul   %ebp,%ebx
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <div_euclid@plt>

LLVM IR (-O0):
define i32 @scale_euclid(i32 %0, i32 %1, i32 %2, i32* %3) {
%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
store i32* %3, i32** %8
%9 = load i32, i32* %5
%10 = ashr i32 %9, 32
%11 = load i32, i32* %6
%12 = ashr i32 %11, 32
%13 = mul nsw i32 %10, %12
%14 = load i32, i32* %5
%15 = ashr i32 %14, 32
%16 = load i32, i32* %6
%17 = call i32 @UINT32_C(i32 -1)
%18 = and i32 %16, %17
%19 = mul nsw i32 %15, %18
%20 = load i32, i32* %5
%21 = call i32 @UINT32_C(i32 -1)
%22 = and i32 %20, %21
%23 = load i32, i32* %6
%24 = call i32 @UINT32_C(i32 -1)
%25 = and i32 %23, %24
%26 = mul nsw i32 %22, %25
%27 = ashr i32 %26, 32
%28 = add nsw i32 %19, %27
%29 = ashr i32 %28, 32
%30 = add nsw i32 %13, %29
%31 = load i32, i32* %5
%32 = call i32 @UINT32_C(i32 -1)
%33 = and i32 %31, %32
%34 = load i32, i32* %6
%35 = ashr i32 %34, 32
%36 = mul nsw i32 %33, %35
%37 = load i32, i32* %5
%38 = ashr i32 %37, 32
%39 = load i32, i32* %6
%40 = call i32 @UINT32_C(i32 -1)
%41 = and i32 %39, %40
%42 = mul nsw i32 %38, %41
%43 = load i32, i32* %5
%44 = call i32 @UINT32_C(i32 -1)
%45 = and i32 %43, %44
%46 = load i32, i32* %6
%47 = call i32 @UINT32_C(i32 -1)
%48 = and i32 %46, %47
%49 = mul nsw i32 %45, %48
%50 = ashr i32 %49, 32
%51 = add nsw i32 %42, %50
%52 = call i32 @UINT32_C(i32 -1)
%53 = and i32 %51, %52
%54 = add nsw i32 %36, %53
%55 = ashr i32 %54, 32
%56 = add nsw i32 %30, %55
%57 = load i32, i32* %5
%58 = load i32, i32* %6
%59 = mul nsw i32 %57, %58
%60 = load i32, i32* %7
%61 = load i32*, i32** %8
%62 = call i32 @div_euclid(i32 %56, i32 %59, i32 %60, i32* %61)
ret i32 %62
}

LLVM IR (-O2):
define i32 @scale_euclid(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = tail call i32 @UINT32_C(i32 -1)
%6 = tail call i32 @UINT32_C(i32 -1)
%7 = tail call i32 @UINT32_C(i32 -1)
%8 = tail call i32 @UINT32_C(i32 -1)
%9 = tail call i32 @UINT32_C(i32 -1)
%10 = tail call i32 @UINT32_C(i32 -1)
%11 = tail call i32 @UINT32_C(i32 -1)
%12 = tail call i32 @UINT32_C(i32 -1)
%13 = mul nsw i32 %1, %0
%14 = tail call i32 @div_euclid(i32 poison, i32 %13, i32 %2, i32* %3)
ret i32 %14
}