#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*/ Ptngc_widediv(unsigned int, unsigned int, unsigned int const,
                                 unsigned int *, unsigned int *);
unsigned int Ptngc_largeint_div(const unsigned int v1,
                                unsigned int *largeint_in,
                                unsigned int *largeint_out, const int n) {
  unsigned int result, remainder = 0;
  int i;
  unsigned int hi;
  hi = 0U;
  i = n;
  while (i) {
    i--;
    Ptngc_widediv(hi, largeint_in[i], v1, &result, &remainder);
    largeint_out[i] = result;
    hi = remainder;
  }
  return remainder;
}


x86 assembly (clang, -O0):
<Ptngc_largeint_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1184 <Ptngc_largeint_div+0x74>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x4(%rbp),%edx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1030 <Ptngc_widediv@plt>
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    113a <Ptngc_largeint_div+0x2a>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Ptngc_largeint_div>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rsp)
test   %ecx,%ecx
je     117b <Ptngc_largeint_div+0x6b>
mov    %ecx,%r13d
mov    %edi,%r12d
movslq %ecx,%rax
neg    %r13d
lea    (%rsi,%rax,4),%rbp
add    $0xfffffffffffffffc,%rbp
lea    (%rdx,%rax,4),%rbx
add    $0xfffffffffffffffc,%rbx
xor    %r14d,%r14d
mov    %rsp,%r15
xor    %edi,%edi
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%r14,4),%esi
mov    %r12d,%edx
lea    0x4(%rsp),%rcx
mov    %r15,%r8
call   1030 <Ptngc_widediv@plt>
mov    0x4(%rsp),%eax
mov    %eax,(%rbx,%r14,4)
mov    (%rsp),%edi
add    $0xffffffffffffffff,%r14
cmp    %r14d,%r13d
jne    1150 <Ptngc_largeint_div+0x40>
jmp    117d <Ptngc_largeint_div+0x6d>
xor    %edi,%edi
mov    %edi,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Ptngc_largeint_div(i32 %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 0, i32* %12
%13 = load i32, i32* %8
store i32 %13, i32* %11
br label %14
14: ; preds = %17, %4
%15 = load i32, i32* %11
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i32, i32* %11
%19 = add nsw i32 %18, -1
store i32 %19, i32* %11
%20 = load i32, i32* %12
%21 = load i32*, i32** %6
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %5
%27 = call i32 @Ptngc_widediv(i32 %20, i32 %25, i32 %26, i32* %9, i32* %10)
%28 = load i32, i32* %9
%29 = load i32*, i32** %7
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
%33 = load i32, i32* %10
store i32 %33, i32* %12
br label %14
34: ; preds = %14
%35 = load i32, i32* %10
ret i32 %35
}

LLVM IR (-O2):
define i32 @Ptngc_largeint_div(i32 %0, i32* nocapture %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%9 = icmp eq i32 %3, 0
br i1 %9, label %24, label %10
10: ; preds = %4
%11 = sext i32 %3 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ %11, %10 ], [ %15, %12 ]
%14 = phi i32 [ 0, %10 ], [ %21, %12 ]
%15 = add nsw i64 %13, -1
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @Ptngc_widediv(i32 %14, i32 %17, i32 %0, i32* %5, i32* %6)
%19 = load i32, i32* %5
%20 = getelementptr inbounds i32, i32* %2, i64 %15
store i32 %19, i32* %20
%21 = load i32, i32* %6
%22 = trunc i64 %15 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %12, %4
%25 = phi i32 [ 0, %4 ], [ %21, %12 ]
ret i32 %25
}