#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 __u64;
typedef int __u32;

/* Variables and functions */
int UINT_MAX;
int /*<<< orphan*/ clocks_calc_mult_shift(int *, int *, int, long, int, int);
int /*<<< orphan*/ printf(char *, int, int);
void clocksource_update_freq_scale(__u32 freq, __u32 width) {
  __u64 sec;
  __u64 mask;
  __u32 mult;
  __u32 shift;
  mask = (__u64)((width) < 64 ? ((1ULL << (width)) - 1) : -1);
  printf(" width: %u mask: %016llx\n", width, mask);
  sec = mask;
  sec /= freq;
  if (!sec)
    sec = 1;
  else if (sec > 600 && mask > UINT_MAX)
    sec = 600;
  clocks_calc_mult_shift(&mult, &shift, freq, 1000000000L, sec, mask);
}


x86 assembly (clang, -O0):
<clocksource_update_freq_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x40,-0x8(%rbp)
jge    1152 <clocksource_update_freq_scale+0x32>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <clocksource_update_freq_scale+0x42>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <clocksource_update_freq_scale+0x42>
mov    -0x20(%rbp),%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11a3 <clocksource_update_freq_scale+0x83>
movl   $0x1,-0xc(%rbp)
jmp    11ce <clocksource_update_freq_scale+0xae>
cmpl   $0x258,-0xc(%rbp)
jle    11c9 <clocksource_update_freq_scale+0xa9>
mov    -0x10(%rbp),%eax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%eax
jle    11c9 <clocksource_update_freq_scale+0xa9>
movl   $0x258,-0xc(%rbp)
jmp    11ce <clocksource_update_freq_scale+0xae>
mov    -0x4(%rbp),%edx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x3b9aca00,%ecx
call   1030 <clocks_calc_mult_shift@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clocksource_update_freq_scale>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xffffffffffffffff,%rax
mov    %esi,%ecx
shl    %cl,%rax
cmp    $0x40,%esi
not    %eax
mov    $0xffffffff,%ebp
cmovl  %eax,%ebp
lea    0xebb(%rip),%rdi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
test   %eax,%eax
je     1173 <clocksource_update_freq_scale+0x53>
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%ebp
mov    $0x258,%r8d
cmovle %eax,%r8d
cmp    $0x259,%eax
cmovl  %eax,%r8d
jmp    1179 <clocksource_update_freq_scale+0x59>
mov    $0x1,%r8d
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x3b9aca00,%ecx
mov    %ebx,%edx
mov    %ebp,%r9d
call   1030 <clocks_calc_mult_shift@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c" width: %u mask: %016llx\0A\00"
@UINT_MAX = global i32 0
define void @clocksource_update_freq_scale(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 64
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = shl i64 1, %13
%15 = sub i64 %14, 1
br label %17
16: ; preds = %2
br label %17
17: ; preds = %16, %11
%18 = phi i64 [ %15, %11 ], [ -1, %16 ]
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %6
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = sdiv i32 %25, %24
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %17
store i32 1, i32* %5
br label %39
30: ; preds = %17
%31 = load i32, i32* %5
%32 = icmp sgt i32 %31, 600
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* %6
%35 = load i32, i32* @UINT_MAX
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 600, i32* %5
br label %38
38: ; preds = %37, %33, %30
br label %39
39: ; preds = %38, %29
%40 = load i32, i32* %3
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = call i32 @clocks_calc_mult_shift(i32* %7, i32* %8, i32 %40, i64 1000000000, i32 %41, i32 %42)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c" width: %u mask: %016llx\0A\00"
@UINT_MAX = global i32 0
define void @clocksource_update_freq_scale(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %1, 64
%8 = zext i32 %1 to i64
%9 = shl nsw i64 -1, %8
%10 = trunc i64 %9 to i32
%11 = xor i32 %10, -1
%12 = select i1 %7, i32 %11, i32 -1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %12)
%14 = sdiv i32 %12, %0
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %2
%17 = icmp sgt i32 %14, 600
%18 = load i32, i32* @UINT_MAX
%19 = icmp sgt i32 %12, %18
%20 = select i1 %17, i1 %19, i1 false
%21 = select i1 %20, i32 600, i32 %14
br label %22
22: ; preds = %16, %2
%23 = phi i32 [ 1, %2 ], [ %21, %16 ]
%24 = call i32 @clocks_calc_mult_shift(i32* %3, i32* %4, i32 %0, i64 1000000000, i32 %23, i32 %12)
ret void
}