#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*/ value;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ ferror(int /*<<< orphan*/);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ mrand48();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ srand48(unsigned long);
int /*<<< orphan*/ stdout;
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int32_t value;
  if (argc >= 2) {
    char *end;
    unsigned long seed;
    seed = strtoul(argv[1], &end, 0);
    if ((*end != '\0') || (seed == 0)) {
      errno = EINVAL;
      perror(argv[1]);
      return 1;
    }
    srand48(seed);
  }
  while (!0) {
    value = mrand48();
    if (fwrite(&value, sizeof(value), 1, stdout) == 1) {
    } else if (ferror(stdout)) {
      perror("fwrite");
      return 1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <main+0x52>
cmpq   $0x0,-0x28(%rbp)
jne    11dd <main+0x7d>
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1260 <main+0x100>
mov    -0x28(%rbp),%rdi
call   1050 <srand48@plt>
jmp    11eb <main+0x8b>
mov    $0x0,%al
call   1040 <mrand48@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%ecx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
jne    121f <main+0xbf>
jmp    125b <main+0xfb>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     124f <main+0xef>
lea    0xdc2(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1260 <main+0x100>
movl   $0x0,-0x4(%rbp)
jmp    1260 <main+0x100>
jmp    11eb <main+0x8b>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1196 <main+0x36>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1070 <strtoul@plt>
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11f8 <main+0x98>
test   %rax,%rax
je     11f8 <main+0x98>
mov    %rax,%rdi
call   1050 <srand48@plt>
mov    0x2e33(%rip),%r14
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <mrand48@plt>
mov    %eax,0xc(%rsp)
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     11b0 <main+0x50>
mov    (%r14),%edi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11ef <main+0x8f>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0a(%rip),%rdi
jmp    120e <main+0xae>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    0x2dd8(%rip),%rcx
mov    %eax,(%rcx)
mov    0x8(%rbx),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    11e7 <main+0x87>

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
@.str = [7 x i8] c"fwrite\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %32
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strtoul(i8* %14, i8** %7, i32 0)
store i64 %15, i64* %8
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = load i64, i64* %8
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20, %11
%24 = load i32, i32* @EINVAL
store i32 %24, i32* @errno
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @perror(i8* %27)
store i32 1, i32* %3
br label %47
29: ; preds = %20
%30 = load i64, i64* %8
%31 = call i32 @srand48(i64 %30)
br label %32
32: ; preds = %29, %2
br label %33
33: ; preds = %32, %46
%34 = call i32 (...) @mrand48()
store i32 %34, i32* %6
%35 = load i32, i32* @stdout
%36 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32 %35)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %33
br label %46
39: ; preds = %33
%40 = load i32, i32* @stdout
%41 = call i64 @ferror(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
45: ; preds = %39
store i32 0, i32* %3
br label %47
46: ; preds = %38
br label %33
47: ; preds = %45, %43, %23
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
@.str = [7 x i8] c"fwrite\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = bitcast i32* %3 to i8*
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %23
7: ; preds = %2
%8 = bitcast i8** %4 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @strtoul(i8* %10, i8** %4, i32 0)
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
%15 = icmp eq i64 %11, 0
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
%19 = load i8*, i8** %9
%20 = tail call i32 @perror(i8* %19)
br label %35
21: ; preds = %7
%22 = tail call i32 @srand48(i64 %11)
br label %23
23: ; preds = %21, %2
br label %24
24: ; preds = %23, %24
%25 = call i32 (...) @mrand48()
store i32 %25, i32* %3
%26 = load i32, i32* @stdout
%27 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %24, label %29
29: ; preds = %24
%30 = load i32, i32* @stdout
%31 = call i64 @ferror(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %17, %29, %33
%36 = phi i32 [ 1, %33 ], [ 0, %29 ], [ 1, %17 ]
ret i32 %36
}