#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*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ next_ord(char *);
int /*<<< orphan*/ next_rnd(char *);
int /*<<< orphan*/ prev_ord(char *);
int /*<<< orphan*/ printf(char *);
char *smalloc(int);
int main(int argc, char **argv) {
  char *filename;
  int n = 25;
  int ordered = 0;
  int asc = 1;
  switch (argc) {
  case 5:
    asc = atoi(argv[4]);
  case 4:
    ordered = atoi(argv[3]);
  case 3:
    n = atoi(argv[2]);
  case 2:
    filename = argv[1];
    break;
  default:
    printf("Incorrect number of arguments!\n");
    exit(0);
    break;
  }
  char *str = smalloc((10 + 1) * sizeof(char));
  if (ordered) {
    for (int i = 0; i < 10; i++)
      str[i] = asc ? 65 : 90;
  } else {
    next_rnd(str);
  }
  FILE *fp = fopen(filename, "w");
  for (int i = 0; i < n; i++) {
    fprintf(fp, "%s\n", str);
    if (ordered) {
      if (asc) {
        next_ord(str);
      } else {
        prev_ord(str);
      }
    } else {
      next_rnd(str);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x19,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x3,%eax
ja     1235 <main+0x95>
mov    -0x50(%rbp),%rax
lea    0xe15(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1248 <main+0xa8>
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0xb,%edi
call   1090 <smalloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12a4 <main+0x104>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    129f <main+0xff>
mov    -0x24(%rbp),%edx
mov    $0x5a,%eax
mov    $0x41,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1267 <main+0xc7>
jmp    12ad <main+0x10d>
mov    -0x30(%rbp),%rdi
call   1040 <next_rnd@plt>
mov    -0x18(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1334 <main+0x194>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd4f(%rip),%rsi
call   1070 <fprintf@plt>
cmpl   $0x0,-0x20(%rbp)
je     1318 <main+0x178>
cmpl   $0x0,-0x24(%rbp)
je     130a <main+0x16a>
mov    -0x30(%rbp),%rdi
call   1060 <next_ord@plt>
jmp    1313 <main+0x173>
mov    -0x30(%rbp),%rdi
call   10c0 <prev_ord@plt>
jmp    1321 <main+0x181>
mov    -0x30(%rbp),%rdi
call   1040 <next_rnd@plt>
jmp    1326 <main+0x186>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12c8 <main+0x128>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
add    $0xfffffffe,%edi
cmp    $0x3,%edi
ja     12cc <main+0x12c>
mov    %rsi,%rbx
mov    $0x1,%r12b
mov    $0x1,%r14d
lea    0xe36(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    0x8(%rbx),%r15
mov    $0xb,%edi
call   1090 <smalloc@plt>
mov    %rax,%rbx
mov    $0x1,%r14d
mov    $0x19,%ebp
jmp    122d <main+0x8d>
mov    0x20(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
sete   %r12b
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%r15
mov    $0xb,%edi
call   1090 <smalloc@plt>
mov    %rax,%rbx
test   %r12b,%r12b
je     123a <main+0x9a>
mov    %rbx,%rdi
call   1050 <next_rnd@plt>
mov    $0x1,%r13b
jmp    125f <main+0xbf>
test   %r14d,%r14d
movabs $0x5a5a5a5a5a5a5a5a,%rax
5a 5a 5a
movabs $0x4141414141414141,%rcx
41 41 41
cmove  %rax,%rcx
mov    %rcx,(%rbx)
mov    %cx,0x8(%rbx)
xor    %r13d,%r13d
lea    0xdaa(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    12b3 <main+0x113>
lea    0xd96(%rip),%r12
jmp    128a <main+0xea>
xchg   %ax,%ax
call   1050 <next_rnd@plt>
add    $0xffffffff,%ebp
je     12b3 <main+0x113>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
test   %r13b,%r13b
jne    1280 <main+0xe0>
test   %r14d,%r14d
je     12ac <main+0x10c>
call   1060 <next_ord@plt>
jmp    1285 <main+0xe5>
call   10c0 <prev_ord@plt>
jmp    1285 <main+0xe5>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd43(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Incorrect number of arguments!\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%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 25, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
%14 = load i32, i32* %4
switch i32 %14, label %34 [
i32 5, label %15
i32 4, label %20
i32 3, label %25
i32 2, label %30
]
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 4
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %9
br label %20
20: ; preds = %2, %15
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %2, %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
br label %30
30: ; preds = %2, %25
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
store i8* %33, i8** %6
br label %37
34: ; preds = %2
%35 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %30
%38 = call i8* @smalloc(i32 11)
store i8* %38, i8** %10
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %59
41: ; preds = %37
store i32 0, i32* %11
br label %42
42: ; preds = %55, %41
%43 = load i32, i32* %11
%44 = icmp slt i32 %43, 10
br i1 %44, label %45, label %58
45: ; preds = %42
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 65, i32 90
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %10
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %45
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %42
58: ; preds = %42
br label %62
59: ; preds = %37
%60 = load i8*, i8** %10
%61 = call i32 @next_rnd(i8* %60)
br label %62
62: ; preds = %59, %58
%63 = load i8*, i8** %6
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %64, i32** %12
store i32 0, i32* %13
br label %65
65: ; preds = %89, %62
%66 = load i32, i32* %13
%67 = load i32, i32* %7
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %92
69: ; preds = %65
%70 = load i32*, i32** %12
%71 = load i8*, i8** %10
%72 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %71)
%73 = load i32, i32* %8
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %69
%76 = load i32, i32* %9
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i8*, i8** %10
%80 = call i32 @next_ord(i8* %79)
br label %84
81: ; preds = %75
%82 = load i8*, i8** %10
%83 = call i32 @prev_ord(i8* %82)
br label %84
84: ; preds = %81, %78
br label %88
85: ; preds = %69
%86 = load i8*, i8** %10
%87 = call i32 @next_rnd(i8* %86)
br label %88
88: ; preds = %85, %84
br label %89
89: ; preds = %88
%90 = load i32, i32* %13
%91 = add nsw i32 %90, 1
store i32 %91, i32* %13
br label %65
92: ; preds = %65
%93 = load i32*, i32** %12
%94 = call i32 @fclose(i32* %93)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@str = [31 x i8] c"Incorrect number of arguments!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %29 [
i32 5, label %7
i32 4, label %11
i32 3, label %17
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i8* @smalloc(i32 11)
br label %32
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 4
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
br label %11
11: ; preds = %2, %7
%12 = phi i32 [ 1, %2 ], [ %10, %7 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp eq i32 %15, 0
br label %17
17: ; preds = %11, %2
%18 = phi i32 [ 1, %2 ], [ %12, %11 ]
%19 = phi i1 [ true, %2 ], [ %16, %11 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i8* @smalloc(i32 11)
br i1 %19, label %32, label %26
26: ; preds = %17
%27 = icmp eq i32 %18, 0
%28 = select i1 %27, i8 90, i8 65
br label %38
29: ; preds = %2
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%31 = tail call i32 @exit(i32 0)
unreachable
32: ; preds = %3, %17
%33 = phi i8* [ %6, %3 ], [ %25, %17 ]
%34 = phi i8* [ %5, %3 ], [ %24, %17 ]
%35 = phi i32 [ 25, %3 ], [ %22, %17 ]
%36 = phi i32 [ 1, %3 ], [ %18, %17 ]
%37 = tail call i32 @next_rnd(i8* %33)
br label %38
38: ; preds = %26, %32
%39 = phi i1 [ true, %32 ], [ false, %26 ]
%40 = phi i8* [ %33, %32 ], [ %25, %26 ]
%41 = phi i8* [ %34, %32 ], [ %24, %26 ]
%42 = phi i32 [ %35, %32 ], [ %22, %26 ]
%43 = phi i32 [ %36, %32 ], [ %18, %26 ]
%44 = tail call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp sgt i32 %42, 0
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = icmp eq i32 %43, 0
br label %50
48: ; preds = %60, %38
%49 = tail call i32 @fclose(i32* %44)
ret i32 0
50: ; preds = %46, %60
%51 = phi i32 [ 0, %46 ], [ %61, %60 ]
%52 = tail call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br i1 %39, label %58, label %53
53: ; preds = %50
br i1 %47, label %56, label %54
54: ; preds = %53
%55 = tail call i32 @next_ord(i8* %40)
br label %60
56: ; preds = %53
%57 = tail call i32 @prev_ord(i8* %40)
br label %60
58: ; preds = %50
%59 = tail call i32 @next_rnd(i8* %40)
br label %60
60: ; preds = %58, %56, %54
%61 = add nuw nsw i32 %51, 1
%62 = icmp eq i32 %61, %42
br i1 %62, label %48, label %50
}