#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*/ assert(int);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ printf(char *);
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int c1 = 4000;
  int c2 = 2000;
  int c3 = 10000;
  int n, v;
  int i, k, j;
  if (argc == 2)
    srandom(atoi(argv[1]));
  else {
    printf("Usage: randomseed\n");
    return -1;
  }
  n = random() % 10;
  k = 0;
  i = 0;
  while (i < n) {
    i++;
    v = random() % 2;
    if (v == 0)
      k += c1;
    else if (v == 1)
      k += c2;
    else
      k += c3;
  }
  j = 0;
  while (j < n) {
    assert(k > 0);
    j++;
    k--;
  }
  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)
movl   $0xfa0,-0x14(%rbp)
movl   $0x7d0,-0x18(%rbp)
movl   $0x2710,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    119e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
jmp    11b6 <main+0x66>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <main+0x132>
mov    $0x0,%al
call   1060 <random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1240 <main+0xf0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1215 <main+0xc5>
mov    -0x14(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    123b <main+0xeb>
cmpl   $0x1,-0x24(%rbp)
jne    122d <main+0xdd>
mov    -0x18(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1236 <main+0xe6>
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    123b <main+0xeb>
jmp    11d6 <main+0x86>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    127b <main+0x12b>
cmpl   $0x0,-0x2c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1247 <main+0xf7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11e3 <main+0x93>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <random@plt>
movslq %eax,%r15
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
test   %r15d,%r15d
jle    1216 <main+0xc6>
mov    $0xfa0,%r14d
mov    %r15d,%ebx
xor    %ebp,%ebp
jmp    11bd <main+0x6d>
nopl   0x0(%rax,%rax,1)
cmp    %ecx,%eax
cmove  %r14d,%edx
add    %edx,%ebp
add    $0xffffffff,%ebx
je     11f7 <main+0xa7>
xor    %eax,%eax
call   1060 <random@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %eax,%esi
sub    %ecx,%esi
mov    $0x7d0,%edx
cmp    $0x1,%esi
je     11b0 <main+0x60>
mov    $0x2710,%edx
jmp    11b0 <main+0x60>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
jmp    1216 <main+0xc6>
xor    %r14d,%r14d
test   %r15d,%r15d
jle    1216 <main+0xc6>
nop
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1050 <assert@plt>
add    $0xffffffff,%ebp
add    $0xffffffff,%r15d
jne    1200 <main+0xb0>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Usage: randomseed\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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4000, i32* %6
store i32 2000, i32* %7
store i32 10000, i32* %8
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
%21 = call i32 @srandom(i32 %20)
br label %24
22: ; preds = %2
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
24: ; preds = %16
%25 = call i32 (...) @random()
%26 = srem i32 %25, 10
store i32 %26, i32* %9
store i32 0, i32* %12
store i32 0, i32* %11
br label %27
27: ; preds = %54, %24
%28 = load i32, i32* %11
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %55
31: ; preds = %27
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
%34 = call i32 (...) @random()
%35 = srem i32 %34, 2
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* %6
%40 = load i32, i32* %12
%41 = add nsw i32 %40, %39
store i32 %41, i32* %12
br label %54
42: ; preds = %31
%43 = load i32, i32* %10
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* %7
%47 = load i32, i32* %12
%48 = add nsw i32 %47, %46
store i32 %48, i32* %12
br label %53
49: ; preds = %42
%50 = load i32, i32* %8
%51 = load i32, i32* %12
%52 = add nsw i32 %51, %50
store i32 %52, i32* %12
br label %53
53: ; preds = %49, %45
br label %54
54: ; preds = %53, %38
br label %27
55: ; preds = %27
store i32 0, i32* %13
br label %56
56: ; preds = %60, %55
%57 = load i32, i32* %13
%58 = load i32, i32* %9
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i32, i32* %12
%62 = icmp sgt i32 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i32, i32* %13
%66 = add nsw i32 %65, 1
store i32 %66, i32* %13
%67 = load i32, i32* %12
%68 = add nsw i32 %67, -1
store i32 %68, i32* %12
br label %56
69: ; preds = %56
store i32 0, i32* %3
br label %70
70: ; preds = %69, %22
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@str = [18 x i8] c"Usage: randomseed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = tail call i32 @srandom(i32 %7)
%9 = tail call i32 (...) @random()
%10 = srem i32 %9, 10
%11 = icmp sgt i32 %10, 0
br i1 %11, label %15, label %36
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %36
14: ; preds = %15
br i1 %11, label %27, label %36
15: ; preds = %4, %15
%16 = phi i32 [ %25, %15 ], [ 0, %4 ]
%17 = phi i32 [ %18, %15 ], [ 0, %4 ]
%18 = add nuw nsw i32 %17, 1
%19 = tail call i32 (...) @random()
%20 = srem i32 %19, 2
%21 = icmp eq i32 %20, 1
%22 = select i1 %21, i32 2000, i32 10000
%23 = icmp eq i32 %20, 0
%24 = select i1 %23, i32 4000, i32 %22
%25 = add nuw nsw i32 %16, %24
%26 = icmp eq i32 %18, %10
br i1 %26, label %14, label %15
27: ; preds = %14, %27
%28 = phi i32 [ %33, %27 ], [ 0, %14 ]
%29 = phi i32 [ %34, %27 ], [ %25, %14 ]
%30 = icmp sgt i32 %29, 0
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = add nuw nsw i32 %28, 1
%34 = add nsw i32 %29, -1
%35 = icmp eq i32 %33, %10
br i1 %35, label %36, label %27
36: ; preds = %27, %4, %14, %12
%37 = phi i32 [ -1, %12 ], [ 0, %14 ], [ 0, %4 ], [ 0, %27 ]
ret i32 %37
}