#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(int **);
int /*<<< orphan*/ free_rng(int *);
double get_rn_dbl(int *);
int *init_rng(int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ print_rng(int *);
int /*<<< orphan*/ printf(char *, ...);
int spawn_rng(int *, int, int ***, int);
int /*<<< orphan*/ stderr;
main() {
  int streamnum, nstreams, *stream, **new;
  double rn;
  int i, irn, nspawned;
  streamnum = 0;
  nstreams = 1;
  stream = init_rng(streamnum, nstreams, 985456376, 0);
  printf(" Print information about stream:\n");
  print_rng(stream);
  printf(" Printing 2 random numbers in [0,1):\n");
  for (i = 0; i < 2; i++) {
    rn = get_rn_dbl(stream);
    printf("%f\n", rn);
  }
  printf(" Spawned two streams\n");
  nspawned = 2;
  nspawned = spawn_rng(stream, 2, &new, !1);
  if (nspawned != 2) {
    fprintf(stderr, "Error: only %d streams spawned\n", nspawned);
    exit(1);
  }
  printf(" Information on first spawned stream:\n");
  print_rng(new[0]);
  printf(" Information on second spawned stream:\n");
  print_rng(new[1]);
  printf(" Printing 2 random numbers from second spawned stream:\n");
  for (i = 0; i < 2; i++) {
    rn = get_rn_dbl(new[1]);
    printf("%f\n", rn);
  }
  free_rng(stream);
  free_rng(new[0]);
  free_rng(new[1]);
  free(new);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x3abcdef8,%edx
xor    %ecx,%ecx
call   1060 <init_rng@plt>
mov    %rax,-0x18(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <print_rng@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    1228 <main+0x98>
mov    -0x18(%rbp),%rdi
call   10b0 <get_rn_dbl@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe35(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ef <main+0x5f>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2,%esi
lea    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <spawn_rng@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
je     1280 <main+0xf0>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
lea    0xdf1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1090 <print_rng@plt>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <print_rng@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    1307 <main+0x177>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <get_rn_dbl@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xd56(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ca <main+0x13a>
mov    -0x18(%rbp),%rdi
call   1080 <free_rng@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1080 <free_rng@plt>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <free_rng@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x3abcdef8,%edx
xor    %ecx,%ecx
call   1070 <init_rng@plt>
mov    %rax,%rbx
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10a0 <print_rng@plt>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10c0 <get_rn_dbl@plt>
lea    0xe17(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10c0 <get_rn_dbl@plt>
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %ecx,%ecx
call   1050 <spawn_rng@plt>
cmp    $0x2,%eax
jne    12d2 <main+0x132>
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   10a0 <print_rng@plt>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rdi
call   10a0 <print_rng@plt>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rdi
call   10c0 <get_rn_dbl@plt>
lea    0xd83(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rdi
call   10c0 <get_rn_dbl@plt>
mov    %r14,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1090 <free_rng@plt>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1090 <free_rng@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rdi
call   1090 <free_rng@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d07(%rip),%rcx
mov    (%rcx),%edi
lea    0xd22(%rip),%rsi
mov    %eax,%edx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c" Print information about stream:\0A\00"
@.str.1 = [38 x i8] c" Printing 2 random numbers in [0,1):\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@.str.3 = [22 x i8] c" Spawned two streams\0A\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"Error: only %d streams spawned\0A\00"
@.str.5 = [39 x i8] c" Information on first spawned stream:\0A\00"
@.str.6 = [40 x i8] c" Information on second spawned stream:\0A\00"
@.str.7 = [56 x i8] c" Printing 2 random numbers from second spawned stream:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32* @init_rng(i32 %10, i32 %11, i32 985456376, i32 0)
store i32* %12, i32** %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** %4
%15 = call i32 @print_rng(i32* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %17
17: ; preds = %25, %0
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = call double @get_rn_dbl(i32* %21)
store double %22, double* %6
%23 = load double, double* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %17
28: ; preds = %17
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %9
%30 = load i32*, i32** %4
%31 = call i32 @spawn_rng(i32* %30, i32 2, i32*** %5, i32 0)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* %9
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %28
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32**, i32*** %5
%42 = getelementptr inbounds i32*, i32** %41, i64 0
%43 = load i32*, i32** %42
%44 = call i32 @print_rng(i32* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32**, i32*** %5
%47 = getelementptr inbounds i32*, i32** %46, i64 1
%48 = load i32*, i32** %47
%49 = call i32 @print_rng(i32* %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %7
br label %51
51: ; preds = %61, %39
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 2
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i32**, i32*** %5
%56 = getelementptr inbounds i32*, i32** %55, i64 1
%57 = load i32*, i32** %56
%58 = call double @get_rn_dbl(i32* %57)
store double %58, double* %6
%59 = load double, double* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %59)
br label %61
61: ; preds = %54
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %51
64: ; preds = %51
%65 = load i32*, i32** %4
%66 = call i32 @free_rng(i32* %65)
%67 = load i32**, i32*** %5
%68 = getelementptr inbounds i32*, i32** %67, i64 0
%69 = load i32*, i32** %68
%70 = call i32 @free_rng(i32* %69)
%71 = load i32**, i32*** %5
%72 = getelementptr inbounds i32*, i32** %71, i64 1
%73 = load i32*, i32** %72
%74 = call i32 @free_rng(i32* %73)
%75 = load i32**, i32*** %5
%76 = call i32 @free(i32** %75)
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
@.str.2 = [4 x i8] c"%f\0A\00"
@stderr = global i32 0
@.str.4 = [32 x i8] c"Error: only %d streams spawned\0A\00"
@str = [33 x i8] c" Print information about stream:\00"
@str.8 = [37 x i8] c" Printing 2 random numbers in [0,1):\00"
@str.9 = [21 x i8] c" Spawned two streams\00"
@str.10 = [38 x i8] c" Information on first spawned stream:\00"
@str.11 = [39 x i8] c" Information on second spawned stream:\00"
@str.12 = [55 x i8] c" Printing 2 random numbers from second spawned stream:\00"
define i32 @main() {
%1 = alloca i32**
%2 = bitcast i32*** %1 to i8*
%3 = tail call i32* @init_rng(i32 0, i32 1, i32 985456376, i32 0)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @print_rng(i32* %3)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0))
%7 = tail call double @get_rn_dbl(i32* %3)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %7)
%9 = tail call double @get_rn_dbl(i32* %3)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 @spawn_rng(i32* %3, i32 2, i32*** %1, i32 0)
%13 = icmp eq i32 %12, 2
br i1 %13, label %18, label %14
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
%20 = load i32**, i32*** %1
%21 = load i32*, i32** %20
%22 = call i32 @print_rng(i32* %21)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
%24 = load i32**, i32*** %1
%25 = getelementptr inbounds i32*, i32** %24, i64 1
%26 = load i32*, i32** %25
%27 = call i32 @print_rng(i32* %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.12, i64 0, i64 0))
%29 = load i32**, i32*** %1
%30 = getelementptr inbounds i32*, i32** %29, i64 1
%31 = load i32*, i32** %30
%32 = call double @get_rn_dbl(i32* %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = load i32**, i32*** %1
%35 = getelementptr inbounds i32*, i32** %34, i64 1
%36 = load i32*, i32** %35
%37 = call double @get_rn_dbl(i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %37)
%39 = call i32 @free_rng(i32* %3)
%40 = load i32**, i32*** %1
%41 = load i32*, i32** %40
%42 = call i32 @free_rng(i32* %41)
%43 = load i32**, i32*** %1
%44 = getelementptr inbounds i32*, i32** %43, i64 1
%45 = load i32*, i32** %44
%46 = call i32 @free_rng(i32* %45)
%47 = load i32**, i32*** %1
%48 = call i32 @free(i32** %47)
ret i32 0
}