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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ srand(unsigned int);
int time(int /*<<< orphan*/ *);
void seed_rand() {
  unsigned int seed;
  FILE *f;
  char s[1024];
  seed = ((unsigned int)(getpid() * time(NULL)));
  srand(seed);
  sprintf(s, "/var/tmp/rand.%d", 0);
  if ((f = fopen(s, "w")) == NULL)
    return;
  fprintf(f, "%u\n", seed);
  fclose(f);
  return;
}


x86 assembly (clang, -O0):
<seed_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x414(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%ecx
mov    -0x414(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <srand@plt>
lea    -0x410(%rbp),%rdi
lea    0xe4b(%rip),%rsi
xor    %edx,%edx
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e2 <seed_rand+0x72>
jmp    11fe <seed_rand+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe23(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seed_rand>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
mov    %ebp,%edi
call   1050 <srand@plt>
lea    0xe64(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1090 <sprintf@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e2 <seed_rand+0x72>
mov    %rax,%rbx
lea    0xe4c(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x408,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/var/tmp/rand.%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define void @seed_rand() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = call i32 (...) @getpid()
%5 = call i32 @time(i32* null)
%6 = mul nsw i32 %4, %5
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = call i32 @srand(i32 %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %0
br label %21
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = load i32, i32* %1
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
br label %21
21: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/var/tmp/rand.%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%u\0A\00"
define void @seed_rand() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 @time(i32* null)
%5 = mul nsw i32 %4, %3
%6 = tail call i32 @srand(i32 %5)
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%12 = tail call i32 @fclose(i32* %8)
br label %13
13: ; preds = %0, %10
ret void
}