#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 BUFSIZ;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int i, j, k, nlines, nchars, ctype;
  char c, buf[BUFSIZ];
  FILE *fp;
  if (argc != 5) {
    printf("usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n");
    exit(2);
  }
  fp = fopen(argv[1], "w");
  nchars = atoi(argv[2]);
  if (nchars > BUFSIZ) {
    printf("Exceeded the maximum limit of the buffer (%d)\n", BUFSIZ);
    exit(3);
  }
  nlines = atoi(argv[3]);
  ctype = atoi(argv[4]);
  k = 0;
  for (i = 1; i <= nlines; i++) {
    if (ctype)
      c = ((i % 2) ? '1' : '0');
    else
      c = 'A' + k;
    for (j = 0; j < nchars; j++)
      buf[j] = c;
    fprintf(fp, "%s\n", buf);
    if (!ctype) {
      if (i != 1 && i % 26 == 0)
        k = 0;
      else
        k++;
    }
  }
  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)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11c4 <main+0x64>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%eax
jle    121f <main+0xbf>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1327 <main+0x1c7>
cmpl   $0x0,-0x28(%rbp)
je     1286 <main+0x126>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x29(%rbp)
jmp    128f <main+0x12f>
mov    -0x1c(%rbp),%eax
add    $0x41,%eax
mov    %al,-0x29(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12be <main+0x15e>
mov    -0x50(%rbp),%rax
mov    -0x29(%rbp),%dl
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1296 <main+0x136>
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x28(%rbp)
jne    1314 <main+0x1b4>
cmpl   $0x1,-0x14(%rbp)
je     1306 <main+0x1a6>
mov    -0x14(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1306 <main+0x1a6>
movl   $0x0,-0x1c(%rbp)
jmp    130f <main+0x1af>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1314 <main+0x1b4>
jmp    1319 <main+0x1b9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124d <main+0xed>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e48(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x5,%edi
jne    12c8 <main+0x148>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    (%r14),%esi
mov    %eax,-0x2c(%rbp)
cmp    %esi,%eax
jg     12de <main+0x15e>
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    12ae <main+0x12e>
mov    %eax,%r12d
mov    0x20(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    -0x2c(%rbp),%eax
mov    %rax,-0x40(%rbp)
neg    %r12d
mov    $0x1,%r14d
xor    %r15d,%r15d
jmp    1235 <main+0xb5>
nopw   0x0(%rax,%rax,1)
lea    (%r12,%r14,1),%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    $0x1,%eax
je     12ae <main+0x12e>
cmpl   $0x0,-0x2c(%rbp)
jle    125f <main+0xdf>
lea    0x41(%r15),%eax
mov    %r14d,%ecx
and    $0x1,%cl
or     $0x30,%cl
test   %ebx,%ebx
movzbl %al,%eax
movzbl %cl,%esi
cmove  %eax,%esi
mov    %r13,%rdi
mov    -0x40(%rbp),%rdx
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
lea    0xdc7(%rip),%rsi
mov    %r13,%rdx
call   1070 <fprintf@plt>
test   %ebx,%ebx
jne    1220 <main+0xa0>
mov    %r14d,%eax
imul   $0x4ec4ec4f,%rax,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
add    $0x1,%r15d
cmp    %r14d,%ecx
mov    %r15d,%eax
mov    $0x0,%ecx
cmove  %ecx,%eax
cmp    $0x1,%r14d
cmove  %r15d,%eax
mov    %eax,%r15d
jmp    1220 <main+0xa0>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xd1d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [60 x i8] c"usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [47 x i8] c"Exceeded the maximum limit of the buffer (%d)\0A\00"
@.str.3 = [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 i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca i8, i64 %17
store i64 %17, i64* %14
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 5
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %15
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = load i32, i32* @BUFSIZ
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %25
%38 = load i32, i32* @BUFSIZ
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 @exit(i32 3)
unreachable
41: ; preds = %25
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %9
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 4
%48 = load i8*, i8** %47
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %11
store i32 0, i32* %8
store i32 1, i32* %6
br label %50
50: ; preds = %99, %41
%51 = load i32, i32* %6
%52 = load i32, i32* %9
%53 = icmp sle i32 %51, %52
br i1 %53, label %54, label %102
54: ; preds = %50
%55 = load i32, i32* %11
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* %6
%59 = srem i32 %58, 2
%60 = icmp ne i32 %59, 0
%61 = zext i1 %60 to i64
%62 = select i1 %60, i32 49, i32 48
%63 = trunc i32 %62 to i8
store i8 %63, i8* %12
br label %68
64: ; preds = %54
%65 = load i32, i32* %8
%66 = add nsw i32 65, %65
%67 = trunc i32 %66 to i8
store i8 %67, i8* %12
br label %68
68: ; preds = %64, %57
store i32 0, i32* %7
br label %69
69: ; preds = %78, %68
%70 = load i32, i32* %7
%71 = load i32, i32* %10
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %81
73: ; preds = %69
%74 = load i8, i8* %12
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %19, i64 %76
store i8 %74, i8* %77
br label %78
78: ; preds = %73
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %69
81: ; preds = %69
%82 = load i32*, i32** %15
%83 = call i32 @fprintf(i32* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%84 = load i32, i32* %11
%85 = icmp ne i32 %84, 0
br i1 %85, label %98, label %86
86: ; preds = %81
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 1
br i1 %88, label %89, label %94
89: ; preds = %86
%90 = load i32, i32* %6
%91 = srem i32 %90, 26
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %89
store i32 0, i32* %8
br label %97
94: ; preds = %89, %86
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
br label %97
97: ; preds = %94, %93
br label %98
98: ; preds = %97, %81
br label %99
99: ; preds = %98
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %50
102: ; preds = %50
%103 = load i32*, i32** %15
%104 = call i32 @fclose(i32* %103)
store i32 0, i32* %3
%105 = load i8*, i8** %13
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [47 x i8] c"Exceeded the maximum limit of the buffer (%d)\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@str = [59 x i8] c"usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 5
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = load i32, i32* @BUFSIZ
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%21 = tail call i32 @exit(i32 3)
unreachable
22: ; preds = %10
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = icmp slt i32 %25, 1
br i1 %26, label %57, label %27
27: ; preds = %22
%28 = getelementptr inbounds i8*, i8** %1, i64 4
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
%31 = icmp eq i32 %30, 0
%32 = icmp sgt i32 %16, 0
%33 = zext i32 %16 to i64
br label %34
34: ; preds = %27, %53
%35 = phi i32 [ 1, %27 ], [ %55, %53 ]
%36 = phi i32 [ 0, %27 ], [ %54, %53 ]
br i1 %32, label %37, label %44
37: ; preds = %34
%38 = trunc i32 %36 to i8
%39 = add i8 %38, 65
%40 = trunc i32 %35 to i8
%41 = and i8 %40, 1
%42 = or i8 %41, 48
%43 = select i1 %31, i8 %39, i8 %42
br label %44
44: ; preds = %37, %34
%45 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br i1 %31, label %46, label %53
46: ; preds = %44
%47 = icmp ne i32 %35, 1
%48 = urem i32 %35, 26
%49 = icmp eq i32 %48, 0
%50 = and i1 %47, %49
%51 = add nsw i32 %36, 1
%52 = select i1 %50, i32 0, i32 %51
br label %53
53: ; preds = %46, %44
%54 = phi i32 [ %36, %44 ], [ %52, %46 ]
%55 = add nuw i32 %35, 1
%56 = icmp eq i32 %35, %25
br i1 %56, label %57, label %34
57: ; preds = %53, %22
%58 = call i32 @fclose(i32* %13)
ret i32 0
}