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

/* Variables and functions */
char *initstate(int, char *, int);
int /*<<< orphan*/ printf(char *, long, long);
int /*<<< orphan*/ puts(char *);
long random();
char *setstate(char *);
int /*<<< orphan*/ srandom(int);
int main(void) {
  int pass;
  int ret = 0;
  long int r[2];
  for (pass = 0; pass < 2; pass++) {
    srandom(0x12344321);
    int j;
    for (j = 0; j < 3; ++j)
      random();
    if (pass == 1) {
      char state[128];
      char *ostate = initstate(0x34562101, state, 128);
      if (setstate(ostate) != state) {
        puts("setstate (ostate) != state");
        ret = 1;
      }
    }
    random();
    r[pass] = random();
  }
  if (r[0] != r[1]) {
    printf("%ld != %ld\n", r[0], r[1]);
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    123d <main+0xdd>
mov    $0x12344321,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11ba <main+0x5a>
mov    $0x0,%al
call   1070 <random@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <main+0x3b>
cmpl   $0x1,-0x8(%rbp)
jne    1215 <main+0xb5>
lea    -0xb0(%rbp),%rsi
mov    $0x34562101,%edi
mov    $0x80,%edx
call   1040 <initstate@plt>
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rdi
call   1080 <setstate@plt>
lea    -0xb0(%rbp),%rcx
cmp    %rcx,%rax
je     1210 <main+0xb0>
lea    0xdfc(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0xc(%rbp)
jmp    1215 <main+0xb5>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
mov    %rcx,-0x20(%rbp,%rax,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <main+0x20>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1266 <main+0x106>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    $0x12344321,%edi
call   1030 <srandom@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rax,%r14
mov    $0x12344321,%edi
call   1030 <srandom@plt>
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
mov    %rsp,%rbx
mov    $0x34562101,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <initstate@plt>
mov    %rax,%rdi
call   1080 <setstate@plt>
cmp    %rbx,%rax
je     11ef <main+0x8f>
lea    0xe1b(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%ebp
xor    %eax,%eax
call   1070 <random@plt>
xor    %eax,%eax
call   1070 <random@plt>
cmp    %rax,%r14
je     1219 <main+0xb9>
lea    0xe12(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"setstate (ostate) != state\00"
@.str.1 = [12 x i8] c"%ld != %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i64]
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %2
br label %8
8: ; preds = %40, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = call i32 @srandom(i32 305414945)
store i32 0, i32* %5
br label %13
13: ; preds = %18, %11
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i64 (...) @random()
br label %18
18: ; preds = %16
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %13
21: ; preds = %13
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%26 = call i8* @initstate(i32 878059777, i8* %25, i32 128)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = call i8* @setstate(i8* %27)
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%30 = icmp ne i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
33: ; preds = %31, %24
br label %34
34: ; preds = %33, %21
%35 = call i64 (...) @random()
%36 = call i64 (...) @random()
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 %38
store i64 %36, i64* %39
br label %40
40: ; preds = %34
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %8
43: ; preds = %8
%44 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%45 = load i64, i64* %44
%46 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
%47 = load i64, i64* %46
%48 = icmp ne i64 %45, %47
br i1 %48, label %49, label %55
49: ; preds = %43
%50 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 0
%51 = load i64, i64* %50
%52 = getelementptr inbounds [2 x i64], [2 x i64]* %4, i64 0, i64 1
%53 = load i64, i64* %52
%54 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %51, i64 %53)
store i32 1, i32* %3
br label %55
55: ; preds = %49, %43
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [27 x i8] c"setstate (ostate) != state\00"
@.str.1 = [12 x i8] c"%ld != %ld\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @srandom(i32 305414945)
%4 = call i64 (...) @random()
%5 = call i64 (...) @random()
%6 = call i64 (...) @random()
%7 = call i64 (...) @random()
%8 = call i64 (...) @random()
%9 = call i32 @srandom(i32 305414945)
%10 = call i64 (...) @random()
%11 = call i64 (...) @random()
%12 = call i64 (...) @random()
%13 = call i8* @initstate(i32 878059777, i8* %2, i32 128)
%14 = call i8* @setstate(i8* %13)
%15 = icmp eq i8* %14, %2
br i1 %15, label %18, label %16
16: ; preds = %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %0, %16
%19 = phi i32 [ 1, %16 ], [ 0, %0 ]
%20 = call i64 (...) @random()
%21 = call i64 (...) @random()
%22 = icmp eq i64 %8, %21
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %8, i64 %21)
br label %25
25: ; preds = %23, %18
%26 = phi i32 [ 1, %23 ], [ %19, %18 ]
ret i32 %26
}