#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 *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
void old_seed() {
  unsigned int seed;
  FILE *f;
  char s[1024];
  sprintf(s, "/var/tmp/rand.%d", 0);
  if ((f = fopen(s, "r")) == NULL)
    return;
  if (fscanf(f, "%u\n", &seed) != 1) {
    fprintf(stderr, "Error reading old random seed\n");
    return;
  }
  fclose(f);
  srand(seed);
  return;
}


x86 assembly (clang, -O0):
<old_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x410(%rbp),%rdi
lea    0xe87(%rip),%rsi
xor    %edx,%edx
call   1080 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a6 <old_seed+0x46>
jmp    11ee <old_seed+0x8e>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11dd <old_seed+0x7d>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ee <old_seed+0x8e>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%edi
call   1050 <srand@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<old_seed>:
push   %rbx
sub    $0x410,%rsp
lea    0xe91(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <sprintf@plt>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d6 <old_seed+0x76>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11c1 <old_seed+0x61>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
call   1050 <srand@plt>
jmp    11d6 <old_seed+0x76>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x410,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"/var/tmp/rand.%d\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%u\0A\00"
@stderr = global i32 0
@.str.3 = [31 x i8] c"Error reading old random seed\0A\00"
define void @old_seed() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %8
8: ; preds = %0
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %18
14: ; preds = %8
%15 = call i32 @fclose(i32* %6)
%16 = load i32, i32* %1
%17 = call i32 @srand(i32 %16)
br label %18
18: ; preds = %0, %14, %11
ret void
}