#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 getpid();
unsigned int random();
int /*<<< orphan*/ srandom(int);
int time(int /*<<< orphan*/ *);
unsigned int __crypt_sha1_iterations(unsigned int hint) {
  static int once = 1;
  if (once) {
    int pid = getpid();
    srandom(time(NULL) ^ (pid * pid));
    once = 0;
  }
  if (hint == 0)
    hint = 24680;
  return hint - (random() % (hint / 4));
}


x86 assembly (clang, -O0):
<__crypt_sha1_iterations>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2eee(%rip)
je     1185 <__crypt_sha1_iterations+0x45>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
xor    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,0x2ebb(%rip)
cmpl   $0x0,-0x4(%rbp)
jne    1196 <__crypt_sha1_iterations+0x56>
movl   $0x6068,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x4(%rbp),%ecx
shr    $0x2,%ecx
xor    %edx,%edx
div    %ecx
mov    -0xc(%rbp),%eax
sub    %edx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__crypt_sha1_iterations>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmpb   $0x0,0x2ef8(%rip)
jne    1171 <__crypt_sha1_iterations+0x31>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <time@plt>
imul   %ebp,%ebp
xor    %eax,%ebp
mov    %ebp,%edi
call   1030 <srandom@plt>
movb   $0x1,0x2ed3(%rip)
test   %ebx,%ebx
mov    $0x6068,%ebp
cmovne %ebx,%ebp
xor    %eax,%eax
call   1060 <random@plt>
mov    %ebp,%ecx
shr    $0x2,%ecx
xor    %edx,%edx
div    %ecx
sub    %edx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__crypt_sha1_iterations.once = internal global i32 1
define i32 @__crypt_sha1_iterations(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @__crypt_sha1_iterations.once
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = call i32 (...) @getpid()
store i32 %7, i32* %3
%8 = call i32 @time(i32* null)
%9 = load i32, i32* %3
%10 = load i32, i32* %3
%11 = mul nsw i32 %9, %10
%12 = xor i32 %8, %11
%13 = call i32 @srandom(i32 %12)
store i32 0, i32* @__crypt_sha1_iterations.once
br label %14
14: ; preds = %6, %1
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 24680, i32* %2
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %2
%20 = call i32 (...) @random()
%21 = load i32, i32* %2
%22 = udiv i32 %21, 4
%23 = urem i32 %20, %22
%24 = sub i32 %19, %23
ret i32 %24
}

LLVM IR (-O2):
@__crypt_sha1_iterations.once = internal unnamed_addr global i1 false
define i32 @__crypt_sha1_iterations(i32 %0) {
%2 = load i1, i1* @__crypt_sha1_iterations.once
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @time(i32* null)
%6 = mul nsw i32 %4, %4
%7 = xor i32 %5, %6
%8 = tail call i32 @srandom(i32 %7)
store i1 true, i1* @__crypt_sha1_iterations.once
br label %9
9: ; preds = %3, %1
%10 = icmp eq i32 %0, 0
%11 = select i1 %10, i32 24680, i32 %0
%12 = tail call i32 (...) @random()
%13 = lshr i32 %11, 2
%14 = urem i32 %12, %13
%15 = sub i32 %11, %14
ret i32 %15
}