#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 /*<<< orphan*/ time_t;

/* Variables and functions */
int /*<<< orphan*/ am_srand(int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void am_randomize(void) {
  time_t my_time = time(NULL);
  char *time_string = ctime(&my_time);
  int i = 0;
  int seed = 0;
  while (time_string[i] != '\0') {
    seed += i * (int)(time_string[i]);
    i += 1;
  }
  am_srand(seed);
}


x86 assembly (clang, -O0):
<am_randomize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <ctime@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119a <am_randomize+0x6a>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
imul   %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115f <am_randomize+0x2f>
mov    -0x18(%rbp),%edi
call   1040 <am_srand@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<am_randomize>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <ctime@plt>
mov    (%rax),%cl
test   %cl,%cl
je     1175 <am_randomize+0x45>
xor    %edx,%edx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl %cl,%ecx
imul   %edx,%ecx
add    %ecx,%ebx
movzbl 0x1(%rax,%rdx,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1160 <am_randomize+0x30>
mov    %ebx,%edi
call   1040 <am_srand@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define void @am_randomize() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = call i8* @ctime(i32* %1)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %15, %7 ], [ 0, %0 ]
%9 = phi i8 [ %17, %7 ], [ %5, %0 ]
%10 = phi i32 [ %14, %7 ], [ 0, %0 ]
%11 = sext i8 %9 to i32
%12 = trunc i64 %8 to i32
%13 = mul nsw i32 %12, %11
%14 = add nsw i32 %13, %10
%15 = add nuw nsw i64 %8, 1
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %7
19: ; preds = %7, %0
%20 = phi i32 [ 0, %0 ], [ %14, %7 ]
%21 = call i32 @am_srand(i32 %20)
ret void
}