#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 void *time_t;
typedef int /*<<< orphan*/ rule_buf;

/* Variables and functions */
int BUFSIZ;
void *atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ generate_random_rule(char *, int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ srand(void *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(void **);
int main(int argc, char *argv[]) {
  if ((argc != 2) && (argc != 3)) {
    fprintf(stderr, "usage: %s number [seed]\n", argv[0]);
    return (-1);
  }
  const int num = atoi(argv[1]);
  if ((num < 1) || (num > 1000000000)) {
    fprintf(stderr, "invalid rule count\n");
    return (-1);
  }
  time_t seed;
  if (argc == 3) {
    seed = atoi(argv[2]);
  } else {
    time(&seed);
  }
  srand(seed);
  int i;
  for (i = 0; i < num; i++) {
    char rule_buf[BUFSIZ];
    memset(rule_buf, 0, sizeof(rule_buf));
    generate_random_rule(rule_buf, 1, 4);
    puts(rule_buf);
  }
  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     11c4 <main+0x54>
cmpl   $0x3,-0x8(%rbp)
je     11c4 <main+0x54>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     11eb <main+0x7b>
cmpl   $0x3b9aca00,-0x14(%rbp)
jle    120e <main+0x9e>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x150>
cmpl   $0x3,-0x8(%rbp)
jne    122e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x20(%rbp)
jmp    1237 <main+0xc7>
lea    -0x20(%rbp),%rdi
call   1080 <time@plt>
mov    -0x20(%rbp),%rdi
call   1060 <srand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12b9 <main+0x149>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <generate_random_rule@plt>
mov    -0x40(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1247 <main+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11c8 <main+0x58>
mov    %edi,%r15d
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %rax,%r12
add    $0xc46535ff,%eax
cmp    $0xc46535ff,%eax
ja     11ec <main+0x7c>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1269 <main+0xf9>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe25(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1269 <main+0xf9>
cmp    $0x3,%r15d
jne    1204 <main+0x94>
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
mov    %rax,%rdi
mov    %rax,-0x28(%rbp)
jmp    1211 <main+0xa1>
lea    -0x28(%rbp),%rdi
call   1080 <time@plt>
mov    -0x28(%rbp),%rdi
call   1060 <srand@plt>
mov    0x2dbb(%rip),%r14
nopl   (%rax)
mov    %rsp,%r15
mov    (%r14),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <generate_random_rule@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r15,%rsp
add    $0xffffffff,%r12d
jne    1220 <main+0xb0>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s number [seed]\0A\00"
@.str.1 = [20 x i8] c"invalid rule count\0A\00"
@BUFSIZ = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %67
22: ; preds = %13, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i8* @atoi(i8* %25)
%27 = ptrtoint i8* %26 to i32
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 1
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = icmp sgt i32 %31, 1000000000
br i1 %32, label %33, label %36
33: ; preds = %30, %22
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %67
36: ; preds = %30
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 3
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i8* @atoi(i8* %42)
store i8* %43, i8** %7
br label %46
44: ; preds = %36
%45 = call i32 @time(i8** %7)
br label %46
46: ; preds = %44, %39
%47 = load i8*, i8** %7
%48 = call i32 @srand(i8* %47)
store i32 0, i32* %8
br label %49
49: ; preds = %63, %46
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %66
53: ; preds = %49
%54 = load i32, i32* @BUFSIZ
%55 = zext i32 %54 to i64
%56 = call i8* @llvm.stacksave()
store i8* %56, i8** %9
%57 = alloca i8, i64 %55
store i64 %55, i64* %10
%58 = trunc i64 %55 to i32
%59 = call i32 @memset(i8* %57, i32 0, i32 %58)
%60 = call i32 @generate_random_rule(i8* %57, i32 1, i32 4)
%61 = call i32 @puts(i8* %57)
%62 = load i8*, i8** %9
br label %63
63: ; preds = %53
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %49
66: ; preds = %49
store i32 0, i32* %3
br label %67
67: ; preds = %66, %33, %16
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s number [seed]\0A\00"
@.str.1 = [20 x i8] c"invalid rule count\0A\00"
@BUFSIZ = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = and i32 %0, -2
%5 = icmp eq i32 %4, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %46
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i8* @atoi(i8* %12)
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
%16 = add i32 %15, -1000000001
%17 = icmp ult i32 %16, -1000000000
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %46
21: ; preds = %10
%22 = bitcast i8** %3 to i8*
%23 = icmp eq i32 %0, 3
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i8* @atoi(i8* %26)
store i8* %27, i8** %3
br label %31
28: ; preds = %21
%29 = call i32 @time(i8** %3)
%30 = load i8*, i8** %3
br label %31
31: ; preds = %24, %28
%32 = phi i8* [ %30, %28 ], [ %27, %24 ]
%33 = call i32 @srand(i8* %32)
br label %34
34: ; preds = %31, %34
%35 = phi i32 [ %43, %34 ], [ 0, %31 ]
%36 = load i32, i32* @BUFSIZ
%37 = zext i32 %36 to i64
%38 = call i8* @llvm.stacksave()
%39 = alloca i8, i64 %37
%40 = call i32 @memset(i8* %39, i32 0, i32 %36)
%41 = call i32 @generate_random_rule(i8* %39, i32 1, i32 4)
%42 = call i32 @puts(i8* %39)
%43 = add nuw nsw i32 %35, 1
%44 = icmp eq i32 %43, %15
br i1 %44, label %45, label %34
45: ; preds = %34
br label %46
46: ; preds = %18, %45, %6
%47 = phi i32 [ -1, %6 ], [ -1, %18 ], [ 0, %45 ]
ret i32 %47
}