#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 */
struct random_data {
  int dummy;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ initstate_r(int, char *, int, struct random_data *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ random_r(struct random_data *, int *);
void *random_printer(void *ptr) {
  int seed = (size_t)ptr;
  struct random_data buff = {};
  int32_t result = 0;
  char statebuf[8];
  initstate_r(seed, statebuf, 8, &buff);
  printf("%p\n", &buff);
  int i;
  for (i = 0; i < 10000; i++) {
    random_r(&buff, &result);
    printf("%d\n", result);
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<random_printer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
lea    -0x18(%rbp),%rcx
call   1070 <initstate_r@plt>
lea    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2710,-0x28(%rbp)
jge    11df <random_printer+0x8f>
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <random_r@plt>
mov    -0x1c(%rbp),%esi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a8 <random_printer+0x58>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_printer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r14
mov    $0x8,%edx
mov    %r14,%rcx
call   1060 <initstate_r@plt>
lea    0xe88(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    $0x2710,%ebp
lea    0x4(%rsp),%r15
lea    0xe73(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <random_r@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    11a0 <random_printer+0x60>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.random_data = type { i32 }
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i8* @random_printer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.random_data
%6 = alloca i32
%7 = alloca [8 x i8]
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = ptrtoint i8* %9 to i64
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
%12 = bitcast %struct.random_data* %5 to i8*
store i32 0, i32* %6
%13 = load i32, i32* %4
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%15 = call i32 @initstate_r(i32 %13, i8* %14, i32 8, %struct.random_data* %5)
%16 = ptrtoint %struct.random_data* %5 to i32
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 0, i32* %8
br label %18
18: ; preds = %25, %1
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 10000
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = call i32 @random_r(%struct.random_data* %5, i32* %6)
%23 = load i32, i32* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %18
28: ; preds = %18
%29 = call i32 @pthread_exit(i32* null)
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
%struct.random_data = type { i32 }
@.str = [4 x i8] c"%p\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define noalias i8* @random_printer(i8* %0) {
%2 = alloca %struct.random_data
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = ptrtoint i8* %0 to i64
%6 = trunc i64 %5 to i32
%7 = bitcast %struct.random_data* %2 to i8*
%8 = getelementptr inbounds %struct.random_data, %struct.random_data* %2, i64 0, i32 0
store i32 0, i32* %8
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%11 = call i32 @initstate_r(i32 %6, i8* %10, i32 8, %struct.random_data* %2)
%12 = ptrtoint %struct.random_data* %2 to i64
%13 = trunc i64 %12 to i32
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %1, %15
%16 = phi i32 [ 0, %1 ], [ %20, %15 ]
%17 = call i32 @random_r(%struct.random_data* %2, i32* %3)
%18 = load i32, i32* %3
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i32 %16, 1
%21 = icmp eq i32 %20, 10000
br i1 %21, label %22, label %15
22: ; preds = %15
%23 = call i32 @pthread_exit(i32* null)
ret i8* undef
}