#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ *pfseed;
int /*<<< orphan*/ printf(char *, unsigned int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
void seedit(const char *flag) {
  FILE *fopen(), *pfseed;
  unsigned int seed2;
  if (flag[0] == 's') {
    pfseed = fopen("seedms", "r");
    if (pfseed == NULL) {
      seed2 = 59243;
    } else {
      fscanf(pfseed, " %d", &seed2);
      fclose(pfseed);
    }
    srand(seed2);
    printf("\n%d\n", seed2);
  } else {
    pfseed = fopen("seedms", "w");
    fprintf(pfseed, "%d \n", rand());
  }
}


x86 assembly (clang, -O0):
<seedit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    11f3 <seedit+0x83>
lea    0xe6d(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ba <seedit+0x4a>
movl   $0xe76b,-0x14(%rbp)
jmp    11d7 <seedit+0x67>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1060 <srand@plt>
mov    -0x14(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
jmp    122b <seedit+0xbb>
lea    0xe06(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xdee(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seedit>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x73,(%rdi)
jne    11b7 <seedit+0x47>
lea    0xe7f(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ea <seedit+0x7a>
mov    %rax,%rbx
lea    0xe6d(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
jmp    11f7 <seedit+0x87>
lea    0xe42(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <rand@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
add    $0x10,%rsp
pop    %rbx
jmp    1070 <fprintf@plt>
movl   $0xe76b,0xc(%rsp)
mov    $0xe76b,%edi
call   1060 <srand@plt>
mov    0xc(%rsp),%esi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"seedms\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [5 x i8] c"\0A%d\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%d \0A\00"
@pfseed = global i32* null
define void @seedit(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 115
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 59243, i32* %4
br label %20
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %15, %14
%21 = load i32, i32* %4
%22 = call i32 @srand(i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %30
25: ; preds = %1
%26 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %26, i32** %3
%27 = load i32*, i32** %3
%28 = call i32 (...) @rand()
%29 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %25, %20
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"seedms\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [5 x i8] c"\0A%d\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [5 x i8] c"%d \0A\00"
@pfseed = global i32* null
define void @seedit(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 115
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %6
store i32 59243, i32* %2
br label %14
10: ; preds = %6
%11 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = call i32 @fclose(i32* %7)
%13 = load i32, i32* %2
br label %14
14: ; preds = %10, %9
%15 = phi i32 [ %13, %10 ], [ 59243, %9 ]
%16 = call i32 @srand(i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %23
19: ; preds = %1
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 (...) @rand()
%22 = tail call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %14
ret void
}