#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
scalar_t__ get_random_number(int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ srandom_linux_libc(int, unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
unsigned int init_random_number(int nr, long seed) {
  if (seed == 0) {
    seed = (long)time(NULL);
    struct timeval current_time;
    gettimeofday(&current_time, NULL);
    seed += (long)current_time.tv_usec;
    seed += get_random_number(1, 1000000);
  }
  srandom_linux_libc(nr, (unsigned int)seed);
  return (unsigned int)seed;
}


x86 assembly (clang, -O0):
<init_random_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <init_random_number+0x57>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
mov    $0xf4240,%esi
call   1050 <get_random_number@plt>
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
call   1060 <srandom_linux_libc@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_random_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
test   %rsi,%rsi
jne    1183 <init_random_number+0x43>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%rbp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
add    0x8(%rsp),%rbp
mov    $0x1,%edi
mov    $0xf4240,%esi
call   1050 <get_random_number@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %r14d,%edi
mov    %ebx,%esi
call   1060 <srandom_linux_libc@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
define i32 @init_random_number(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca %struct.timeval
store i32 %0, i32* %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = call i64 @time(i32* null)
store i64 %9, i64* %4
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* %4
%14 = add nsw i64 %13, %12
store i64 %14, i64* %4
%15 = call i64 @get_random_number(i32 1, i32 1000000)
%16 = load i64, i64* %4
%17 = add nsw i64 %16, %15
store i64 %17, i64* %4
br label %18
18: ; preds = %8, %2
%19 = load i32, i32* %3
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
%22 = call i32 @srandom_linux_libc(i32 %19, i32 %21)
%23 = load i64, i64* %4
%24 = trunc i64 %23 to i32
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
define i32 @init_random_number(i32 %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i64 @time(i32* null)
%7 = bitcast %struct.timeval* %3 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = add nsw i64 %10, %6
%12 = tail call i64 @get_random_number(i32 1, i32 1000000)
%13 = add nsw i64 %11, %12
br label %14
14: ; preds = %5, %2
%15 = phi i64 [ %13, %5 ], [ %1, %2 ]
%16 = trunc i64 %15 to i32
%17 = tail call i32 @srandom_linux_libc(i32 %0, i32 %16)
ret i32 %16
}