#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*/ scale_binary_value(long, int *, unsigned int *);
void update_bit_len(unsigned p, unsigned q, int *nbits, unsigned *frac) {
  long x;
  unsigned f2;
  x = ((long)q << 16) / p;
  scale_binary_value(x, nbits, &f2);
  x = (long)f2 * (long)*frac;
  x >>= 16;
  x += f2;
  x += *frac;
  x += 0x10000L;
  scale_binary_value(x, nbits, frac);
}


x86 assembly (clang, -O0):
<update_bit_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x10,%rax
mov    -0x4(%rbp),%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <scale_binary_value@plt>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
imul   %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sar    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x10000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <scale_binary_value@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_bit_len>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%eax
shl    $0x10,%rax
mov    %edi,%ecx
movabs $0xffff00000000,%rdx
test   %rdx,%rax
je     1138 <update_bit_len+0x28>
xor    %edx,%edx
div    %rcx
jmp    113c <update_bit_len+0x2c>
xor    %edx,%edx
div    %ecx
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <scale_binary_value@plt>
mov    0x4(%rsp),%eax
mov    (%r14),%ecx
mov    %rcx,%rdx
imul   %rax,%rdx
shr    $0x10,%rdx
add    %rcx,%rax
lea    (%rdx,%rax,1),%rdi
add    $0x10000,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <scale_binary_value@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @update_bit_len(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = shl i64 %12, 16
%14 = load i32, i32* %5
%15 = zext i32 %14 to i64
%16 = sdiv i64 %13, %15
store i64 %16, i64* %9
%17 = load i64, i64* %9
%18 = load i32*, i32** %7
%19 = call i32 @scale_binary_value(i64 %17, i32* %18, i32* %10)
%20 = load i32, i32* %10
%21 = zext i32 %20 to i64
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = zext i32 %23 to i64
%25 = mul nsw i64 %21, %24
store i64 %25, i64* %9
%26 = load i64, i64* %9
%27 = ashr i64 %26, 16
store i64 %27, i64* %9
%28 = load i32, i32* %10
%29 = zext i32 %28 to i64
%30 = load i64, i64* %9
%31 = add nsw i64 %30, %29
store i64 %31, i64* %9
%32 = load i32*, i32** %8
%33 = load i32, i32* %32
%34 = zext i32 %33 to i64
%35 = load i64, i64* %9
%36 = add nsw i64 %35, %34
store i64 %36, i64* %9
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 65536
store i64 %38, i64* %9
%39 = load i64, i64* %9
%40 = load i32*, i32** %7
%41 = load i32*, i32** %8
%42 = call i32 @scale_binary_value(i64 %39, i32* %40, i32* %41)
ret void
}

LLVM IR (-O2):
define void @update_bit_len(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = zext i32 %1 to i64
%8 = shl nuw nsw i64 %7, 16
%9 = zext i32 %0 to i64
%10 = udiv i64 %8, %9
%11 = call i32 @scale_binary_value(i64 %10, i32* %2, i32* %5)
%12 = load i32, i32* %5
%13 = zext i32 %12 to i64
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = mul nuw nsw i64 %15, %13
%17 = lshr i64 %16, 16
%18 = add nuw nsw i64 %13, 65536
%19 = add nuw nsw i64 %18, %15
%20 = add nuw nsw i64 %19, %17
%21 = call i32 @scale_binary_value(i64 %20, i32* %2, i32* %3)
ret void
}