#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ putstx(char *);
int /*<<< orphan*/ rnd(unsigned char *, unsigned char *);
int /*<<< orphan*/ shwsd(unsigned int, unsigned char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i;
  int kount;
  unsigned int cseed;
  unsigned int emm;
  unsigned char *sd;
  unsigned char *sd2;
  unsigned char *p, *q;
  if (argc != 2)
    putstx(*argv);
  kount = atoi(*(argv + 1));
  if (kount < 1) {
    fprintf(stderr,
            "main: kount %s is "
            "less than one\n",
            *(argv + 1));
    putstx(*argv);
  }
  if (kount > 65535) {
    fprintf(stderr,
            "main: kount %s is "
            "greater than 10 thousand\n",
            *(argv + 1));
    putstx(*argv);
  }
  sd = (unsigned char *)malloc(64);
  if (sd == NULL) {
    fprintf(stderr, "main: out of memory "
                    "allocating sd\n");
    exit(1);
  }
  sd2 = (unsigned char *)malloc(64);
  if (sd == NULL) {
    fprintf(stderr, "main: out of memory "
                    "allocating sd2\n");
    exit(1);
  }
  p = (unsigned char *)sd;
  q = (unsigned char *)sd + 64;
  while (p < q)
    *p++ = '\0';
  p = (unsigned char *)sd2;
  q = (unsigned char *)sd2 + 64;
  while (p < q)
    *p++ = '\0';
  p = (unsigned char *)sd;
  *p = 1;
  emm = 65539;
  cseed = 1;
  shwsd(cseed, sd);
  i = kount;
  while (i--) {
    cseed *= emm;
    rnd(sd, sd2);
  }
  shwsd(cseed, sd);
  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)
je     119c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <putstx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    11e1 <main+0x71>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <putstx@plt>
cmpl   $0xffff,-0x18(%rbp)
jle    1219 <main+0xa9>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <putstx@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1253 <main+0xe3>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128d <main+0x11d>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12c6 <main+0x156>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
jmp    12a1 <main+0x131>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12ff <main+0x18f>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
jmp    12da <main+0x16a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x1,(%rax)
movl   $0x10003,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <shwsd@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     135e <main+0x1ee>
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <rnd@plt>
jmp    132e <main+0x1be>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <shwsd@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
je     1187 <main+0x17>
mov    (%r14),%rdi
call   1070 <putstx@plt>
mov    0x8(%r14),%rbp
mov    %rbp,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11aa <main+0x3a>
cmp    $0x10000,%ebx
jb     11cc <main+0x5c>
lea    0xe79(%rip),%rsi
jmp    11b1 <main+0x41>
lea    0xe4f(%rip),%rsi
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%rdi
call   1070 <putstx@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     126d <main+0xfd>
mov    %rax,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xorps  %xmm0,%xmm0
movups %xmm0,0x1(%r14)
movups %xmm0,0x11(%r14)
movups %xmm0,0x21(%r14)
movups %xmm0,0x30(%r14)
movups %xmm0,0x30(%rax)
movups %xmm0,0x20(%rax)
movups %xmm0,0x10(%rax)
movups %xmm0,(%rax)
movb   $0x1,(%r14)
mov    $0x1,%ebp
mov    $0x1,%edi
mov    %r14,%rsi
call   1030 <shwsd@plt>
test   %ebx,%ebx
je     1256 <main+0xe6>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
imul   $0x10003,%ebp,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <rnd@plt>
add    $0xffffffff,%ebx
jne    1240 <main+0xd0>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <shwsd@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"main: kount %s is less than one\0A\00"
@.str.1 = [44 x i8] c"main: kount %s is greater than 10 thousand\0A\00"
@.str.2 = [35 x i8] c"main: out of memory allocating sd\0A\00"
@.str.3 = [36 x i8] c"main: out of memory allocating sd2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = call i32 @putstx(i8* %18)
br label %20
20: ; preds = %16, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %36
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = call i32 @putstx(i8* %34)
br label %36
36: ; preds = %27, %20
%37 = load i32, i32* %7
%38 = icmp sgt i32 %37, 65535
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i8**, i8*** %5
%46 = load i8*, i8** %45
%47 = call i32 @putstx(i8* %46)
br label %48
48: ; preds = %39, %36
%49 = call i64 @malloc(i32 64)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = call i64 @malloc(i32 64)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %11
%60 = load i8*, i8** %10
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %66
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %57
%67 = load i8*, i8** %10
store i8* %67, i8** %12
%68 = load i8*, i8** %10
%69 = getelementptr inbounds i8, i8* %68, i64 64
store i8* %69, i8** %13
br label %70
70: ; preds = %74, %66
%71 = load i8*, i8** %12
%72 = load i8*, i8** %13
%73 = icmp ult i8* %71, %72
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i8*, i8** %12
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %12
store i8 0, i8* %75
br label %70
77: ; preds = %70
%78 = load i8*, i8** %11
store i8* %78, i8** %12
%79 = load i8*, i8** %11
%80 = getelementptr inbounds i8, i8* %79, i64 64
store i8* %80, i8** %13
br label %81
81: ; preds = %85, %77
%82 = load i8*, i8** %12
%83 = load i8*, i8** %13
%84 = icmp ult i8* %82, %83
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i8*, i8** %12
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %12
store i8 0, i8* %86
br label %81
88: ; preds = %81
%89 = load i8*, i8** %10
store i8* %89, i8** %12
%90 = load i8*, i8** %12
store i8 1, i8* %90
store i32 65539, i32* %9
store i32 1, i32* %8
%91 = load i32, i32* %8
%92 = load i8*, i8** %10
%93 = call i32 @shwsd(i32 %91, i8* %92)
%94 = load i32, i32* %7
store i32 %94, i32* %6
br label %95
95: ; preds = %99, %88
%96 = load i32, i32* %6
%97 = add nsw i32 %96, -1
store i32 %97, i32* %6
%98 = icmp ne i32 %96, 0
br i1 %98, label %99, label %106
99: ; preds = %95
%100 = load i32, i32* %9
%101 = load i32, i32* %8
%102 = mul i32 %101, %100
store i32 %102, i32* %8
%103 = load i8*, i8** %10
%104 = load i8*, i8** %11
%105 = call i32 @rnd(i8* %103, i8* %104)
br label %95
106: ; preds = %95
%107 = load i32, i32* %8
%108 = load i8*, i8** %10
%109 = call i32 @shwsd(i32 %107, i8* %108)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"main: kount %s is less than one\0A\00"
@.str.1 = [44 x i8] c"main: kount %s is greater than 10 thousand\0A\00"
@.str.2 = [35 x i8] c"main: out of memory allocating sd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @putstx(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = icmp slt i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = icmp ugt i32 %10, 65535
br i1 %13, label %14, label %20
14: ; preds = %12, %7
%15 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), %12 ]
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* %15, i8* %9)
%18 = load i8*, i8** %1
%19 = tail call i32 @putstx(i8* %18)
br label %20
20: ; preds = %14, %12
%21 = tail call i64 @malloc(i32 64)
%22 = inttoptr i64 %21 to i8*
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = tail call i64 @malloc(i32 64)
%30 = getelementptr inbounds i8, i8* %22, i64 1
%31 = inttoptr i64 %29 to i8*
store i8 1, i8* %22
%32 = tail call i32 @shwsd(i32 1, i8* %22)
%33 = icmp eq i32 %10, 0
br i1 %33, label %41, label %34
34: ; preds = %28, %34
%35 = phi i32 [ %37, %34 ], [ %10, %28 ]
%36 = phi i32 [ %38, %34 ], [ 1, %28 ]
%37 = add nsw i32 %35, -1
%38 = mul i32 %36, 65539
%39 = tail call i32 @rnd(i8* %22, i8* %31)
%40 = icmp eq i32 %37, 0
br i1 %40, label %41, label %34
41: ; preds = %34, %28
%42 = phi i32 [ 1, %28 ], [ %38, %34 ]
%43 = tail call i32 @shwsd(i32 %42, i8* %22)
ret i32 0
}