#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 RAND_MAX;
int /*<<< orphan*/ errno;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ random();
int /*<<< orphan*/ srandom(unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int32_t value;
  if ((argc >= 2) && (strcmp(argv[1], "-v") == 0)) {
    const char *program;
    fprintf(stderr, "%s: RAND_MAX=%u\n",
            ((program = strrchr(argv[0], '/')) == (char *)0) ? argv[0]
                                                             : program + 1,
            RAND_MAX);
    --argc;
    ++argv;
  }
  if (argc >= 2) {
    char *end;
    unsigned long seed;
    seed = strtoul(argv[1], &end, 0);
    if (*end != '\0') {
      errno = EINVAL;
      perror(argv[1]);
      return 1;
    }
    srandom((unsigned int)seed);
  }
  while (!0) {
    value = random();
    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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1246 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1246 <main+0xb6>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1209 <main+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1215 <main+0x85>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    0x2dc5(%rip),%rax
mov    (%rax),%ecx
lea    0xdd7(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     12ad <main+0x11d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a2 <main+0x112>
mov    0x2d4a(%rip),%rax
mov    (%rax),%ecx
mov    0x2d49(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1327 <main+0x197>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
call   1030 <srandom@plt>
jmp    12b2 <main+0x122>
mov    $0x0,%al
call   1080 <random@plt>
mov    %eax,-0x14(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%ecx
lea    -0x14(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
jne    12e6 <main+0x156>
jmp    1322 <main+0x192>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1316 <main+0x186>
lea    0xd0f(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1327 <main+0x197>
movl   $0x0,-0x4(%rbp)
jmp    1327 <main+0x197>
jmp    12b2 <main+0x122>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1230 <main+0xa0>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1206 <main+0x76>
mov    0x2e14(%rip),%rax
mov    (%rax),%r14d
mov    (%rbx),%r15
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rdx
test   %rax,%rax
cmove  %r15,%rdx
mov    0x2dff(%rip),%rax
mov    (%rax),%ecx
lea    0xe11(%rip),%rsi
mov    %r14d,%edi
call   1070 <fprintf@plt>
add    $0xfffffffd,%ebp
cmp    $0xfffffffe,%ebp
jae    1230 <main+0xa0>
add    $0x8,%rbx
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   10a0 <strtoul@plt>
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1283 <main+0xf3>
mov    %eax,%edi
call   1030 <srandom@plt>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <random@plt>
mov    %eax,0xc(%rsp)
mov    0x2d7c(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
cmp    $0x1,%eax
je     1230 <main+0xa0>
mov    0x0(%rbp),%edi
call   1040 <ferror@plt>
test   %rax,%rax
jne    127a <main+0xea>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd93(%rip),%rdi
jmp    1299 <main+0x109>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    0x2d3d(%rip),%rcx
mov    %eax,(%rcx)
mov    0x8(%rbx),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
jmp    126d <main+0xdd>

LLVM IR (-O0):
@.str = [3 x i8] c"-v\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"%s: RAND_MAX=%u\0A\00"
@RAND_MAX = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
@.str.2 = [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 i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %40
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i8* @strrchr(i8* %22, i8 signext 47)
store i8* %23, i8** %7
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
br label %32
29: ; preds = %18
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 1
br label %32
32: ; preds = %29, %25
%33 = phi i8* [ %28, %25 ], [ %31, %29 ]
%34 = load i32, i32* @RAND_MAX
%35 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %34)
%36 = load i32, i32* %4
%37 = add nsw i32 %36, -1
store i32 %37, i32* %4
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i32 1
store i8** %39, i8*** %5
br label %40
40: ; preds = %32, %12, %2
%41 = load i32, i32* %4
%42 = icmp sge i32 %41, 2
br i1 %42, label %43, label %62
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @strtoul(i8* %46, i8** %8, i32 0)
store i64 %47, i64* %9
%48 = load i8*, i8** %8
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %43
%53 = load i32, i32* @EINVAL
store i32 %53, i32* @errno
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 @perror(i8* %56)
store i32 1, i32* %3
br label %77
58: ; preds = %43
%59 = load i64, i64* %9
%60 = trunc i64 %59 to i32
%61 = call i32 @srandom(i32 %60)
br label %62
62: ; preds = %58, %40
br label %63
63: ; preds = %62, %76
%64 = call i32 (...) @random()
store i32 %64, i32* %6
%65 = load i32, i32* @stdout
%66 = call i32 @fwrite(i32* %6, i32 4, i32 1, i32 %65)
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %69
68: ; preds = %63
br label %76
69: ; preds = %63
%70 = load i32, i32* @stdout
%71 = call i64 @ferror(i32 %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %77
75: ; preds = %69
store i32 0, i32* %3
br label %77
76: ; preds = %68
br label %63
77: ; preds = %75, %73, %52
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"-v\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"%s: RAND_MAX=%u\0A\00"
@RAND_MAX = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
@.str.2 = [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 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %14, i8 signext 47)
%16 = icmp eq i8* %15, null
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = select i1 %16, i8* %14, i8* %17
%19 = load i32, i32* @RAND_MAX
%20 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = add nsw i32 %0, -3
%22 = icmp ult i32 %21, -2
br i1 %22, label %24, label %23
23: ; preds = %2, %33, %12
br label %40
24: ; preds = %7, %12
%25 = phi i8** [ %8, %12 ], [ %1, %7 ]
%26 = bitcast i8** %4 to i8*
%27 = getelementptr inbounds i8*, i8** %25, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strtoul(i8* %28, i8** %4, i32 0)
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = trunc i64 %29 to i32
%35 = tail call i32 @srandom(i32 %34)
br label %23
36: ; preds = %24
%37 = load i32, i32* @EINVAL
store i32 %37, i32* @errno
%38 = load i8*, i8** %27
%39 = tail call i32 @perror(i8* %38)
br label %51
40: ; preds = %23, %40
%41 = call i32 (...) @random()
store i32 %41, i32* %3
%42 = load i32, i32* @stdout
%43 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %42)
%44 = icmp eq i32 %43, 1
br i1 %44, label %40, label %45
45: ; preds = %40
%46 = load i32, i32* @stdout
%47 = call i64 @ferror(i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %36, %45, %49
%52 = phi i32 [ 1, %49 ], [ 1, %36 ], [ 0, %45 ]
ret i32 %52
}