#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 uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int div_with_reminder(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int hi_dword(int);
int lo_dword(int);
uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uint32_t divisor,
                   uint64_t *quotient_hi, uint64_t *quotient_lo) {
  uint64_t dividend_dwords[4];
  uint32_t remainder = 0;
  dividend_dwords[3] = hi_dword(dividend_hi);
  dividend_dwords[2] = lo_dword(dividend_hi);
  dividend_dwords[1] = hi_dword(dividend_lo);
  dividend_dwords[0] = lo_dword(dividend_lo);
  *quotient_hi = div_with_reminder(dividend_dwords[3], divisor, &remainder)
                 << 32;
  *quotient_hi |= div_with_reminder(dividend_dwords[2], divisor, &remainder);
  *quotient_lo = div_with_reminder(dividend_dwords[1], divisor, &remainder)
                 << 32;
  *quotient_lo |= div_with_reminder(dividend_dwords[0], divisor, &remainder);
  return remainder;
}


x86 assembly (clang, -O0):
<div128_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <hi_dword@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <lo_dword@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <hi_dword@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <lo_dword@plt>
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x34(%rbp),%rdx
call   1040 <div_with_reminder@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x34(%rbp),%rdx
call   1040 <div_with_reminder@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x34(%rbp),%rdx
call   1040 <div_with_reminder@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x34(%rbp),%rdx
call   1040 <div_with_reminder@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<div128_32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %edx,%ebp
mov    %esi,%r12d
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
call   1050 <hi_dword@plt>
mov    %eax,%r13d
mov    %ebx,%edi
call   1030 <lo_dword@plt>
mov    %eax,%ebx
mov    %r12d,%edi
call   1050 <hi_dword@plt>
mov    %eax,%r14d
mov    %r12d,%edi
call   1030 <lo_dword@plt>
mov    %eax,%r12d
lea    0x4(%rsp),%r15
mov    %r13d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <div_with_reminder@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <div_with_reminder@plt>
mov    0x8(%rsp),%rcx
or     %eax,(%rcx)
mov    %r14d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <div_with_reminder@plt>
mov    %r12d,%edi
mov    %ebp,%esi
mov    %r15,%rdx
call   1040 <div_with_reminder@plt>
mov    0x10(%rsp),%rcx
or     %eax,(%rcx)
mov    0x4(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @div128_32(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [4 x i32]
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 0, i32* %12
%13 = load i32, i32* %6
%14 = call i32 @hi_dword(i32 %13)
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
store i32 %14, i32* %15
%16 = load i32, i32* %6
%17 = call i32 @lo_dword(i32 %16)
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
store i32 %17, i32* %18
%19 = load i32, i32* %7
%20 = call i32 @hi_dword(i32 %19)
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
store i32 %20, i32* %21
%22 = load i32, i32* %7
%23 = call i32 @lo_dword(i32 %22)
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
store i32 %23, i32* %24
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 3
%26 = load i32, i32* %25
%27 = load i32, i32* %8
%28 = call i32 @div_with_reminder(i32 %26, i32 %27, i32* %12)
%29 = shl i32 %28, 32
%30 = load i32*, i32** %9
store i32 %29, i32* %30
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 2
%32 = load i32, i32* %31
%33 = load i32, i32* %8
%34 = call i32 @div_with_reminder(i32 %32, i32 %33, i32* %12)
%35 = load i32*, i32** %9
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 1
%39 = load i32, i32* %38
%40 = load i32, i32* %8
%41 = call i32 @div_with_reminder(i32 %39, i32 %40, i32* %12)
%42 = shl i32 %41, 32
%43 = load i32*, i32** %10
store i32 %42, i32* %43
%44 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%45 = load i32, i32* %44
%46 = load i32, i32* %8
%47 = call i32 @div_with_reminder(i32 %45, i32 %46, i32* %12)
%48 = load i32*, i32** %10
%49 = load i32, i32* %48
%50 = or i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* %12
ret i32 %51
}

LLVM IR (-O2):
define i32 @div128_32(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i32* nocapture %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%8 = tail call i32 @hi_dword(i32 %0)
%9 = tail call i32 @lo_dword(i32 %0)
%10 = tail call i32 @hi_dword(i32 %1)
%11 = tail call i32 @lo_dword(i32 %1)
%12 = call i32 @div_with_reminder(i32 %8, i32 %2, i32* %6)
%13 = call i32 @div_with_reminder(i32 %9, i32 %2, i32* %6)
%14 = load i32, i32* %3
%15 = or i32 %14, %13
store i32 %15, i32* %3
%16 = call i32 @div_with_reminder(i32 %10, i32 %2, i32* %6)
%17 = call i32 @div_with_reminder(i32 %11, i32 %2, i32* %6)
%18 = load i32, i32* %4
%19 = or i32 %18, %17
store i32 %19, i32* %4
%20 = load i32, i32* %6
ret i32 %20
}