#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*/ clrscr();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char *getstring(int);
scalar_t__ isdigit(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  char *csv_buffer = (char *)malloc(255);
  char *filename_buffer = (char *)malloc(50);
  FILE *file_handle;
  int arg_num;
  clrscr();
  if (argc == 2) {
    for (int i = 0; i < strlen(argv[1]); i++) {
      if (isdigit(argv[1][i])) {
        arg_num = atoi(argv[1]);
      } else {
        printf("You did not enter a number. Exiting...\n");
        exit(1);
      }
    }
    printf("Enter a filename of your choice,\n ");
    printf("  No filename extension needed:  ");
    filename_buffer = getstring(50);
    strcat(filename_buffer, ".csv");
    printf("Your filename will be: %s \n", filename_buffer);
    if (file_handle = fopen(filename_buffer, "a+")) {
      for (int c = 0; c < arg_num; c++) {
        printf("Enter a line of CSV data, separated by commas:\n ");
        csv_buffer = getstring(255);
        csv_buffer[strlen(csv_buffer)] = '\n';
        fputs(csv_buffer, file_handle);
      }
    } else {
      printf("Could not open file: %s\n", filename_buffer);
      exit(1);
    }
  } else {
    printf("Usage: csv 'num' : where 'num' is\n");
    printf("         quantity of csv records you desire.\n");
  }
  fclose(file_handle);
}


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    $0xff,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x32,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <clrscr@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1384 <main+0x1c4>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jae    128e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1263 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    127b <main+0xbb>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1280 <main+0xc0>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    120a <main+0x4a>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x32,%edi
call   1030 <getstring@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x20(%rbp),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1363 <main+0x1a3>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    135e <main+0x19e>
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0xff,%edi
call   1030 <getstring@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <fputs@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ff <main+0x13f>
jmp    137f <main+0x1bf>
mov    -0x20(%rbp),%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    13a0 <main+0x1e0>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0xff,%edi
call   10b0 <malloc@plt>
mov    $0x32,%edi
call   10b0 <malloc@plt>
xor    %eax,%eax
call   1050 <clrscr@plt>
cmp    $0x2,%ebx
jne    1333 <main+0x163>
mov    0x8(%r14),%rax
mov    (%rax),%al
test   %al,%al
je     1265 <main+0x95>
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1243 <main+0x73>
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
cmp    %rbp,%rax
jbe    1259 <main+0x89>
movsbl (%rbx,%rbp,1),%edi
call   1040 <isdigit@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1220 <main+0x50>
lea    0xeb8(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebp
jmp    1265 <main+0x95>
lea    0xd94(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x32,%edi
call   1030 <getstring@plt>
mov    %rax,%r15
lea    0xdb0(%rip),%rsi
mov    %rax,%rdi
call   10e0 <strcat@plt>
lea    0xda6(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdb1(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1318 <main+0x148>
mov    %rax,%r14
test   %ebp,%ebp
jle    1303 <main+0x133>
lea    0xd99(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xff,%edi
call   1030 <getstring@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <strlen@plt>
movb   $0xa,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <fputs@plt>
add    $0xffffffff,%ebp
jne    12d0 <main+0x100>
mov    %r14,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd79(%rip),%rdi
call   1060 <puts@plt>
lea    0xd8f(%rip),%rdi
call   1060 <puts@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"You did not enter a number. Exiting...\0A\00"
@.str.1 = [35 x i8] c"Enter a filename of your choice,\0A \00"
@.str.2 = [34 x i8] c" No filename extension needed: \00"
@.str.3 = [5 x i8] c".csv\00"
@.str.4 = [28 x i8] c"Your filename will be: %s \0A\00"
@.str.5 = [3 x i8] c"a+\00"
@.str.6 = [49 x i8] c"Enter a line of CSV data, separated by commas:\0A \00"
@.str.7 = [25 x i8] c"Could not open file: %s\0A\00"
@.str.8 = [35 x i8] c"Usage: csv 'num' : where 'num' is\0A\00"
@.str.9 = [46 x i8] c" quantity of csv records you desire.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 @malloc(i32 255)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = call i64 @malloc(i32 50)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
%16 = call i32 (...) @clrscr()
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %85
19: ; preds = %2
store i32 0, i32* %10
br label %20
20: ; preds = %47, %19
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strlen(i8* %25)
%27 = icmp ult i64 %22, %26
br i1 %27, label %28, label %50
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i64 @isdigit(i8 signext %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %28
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %9
br label %46
43: ; preds = %28
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
br label %47
47: ; preds = %46
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %20
50: ; preds = %20
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%53 = call i8* @getstring(i32 50)
store i8* %53, i8** %7
%54 = load i8*, i8** %7
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%56 = load i8*, i8** %7
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = load i8*, i8** %7
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %59, i32** %8
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %80
61: ; preds = %50
store i32 0, i32* %11
br label %62
62: ; preds = %76, %61
%63 = load i32, i32* %11
%64 = load i32, i32* %9
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %79
66: ; preds = %62
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%68 = call i8* @getstring(i32 255)
store i8* %68, i8** %6
%69 = load i8*, i8** %6
%70 = load i8*, i8** %6
%71 = call i64 @strlen(i8* %70)
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 10, i8* %72
%73 = load i8*, i8** %6
%74 = load i32*, i32** %8
%75 = call i32 @fputs(i8* %73, i32* %74)
br label %76
76: ; preds = %66
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %62
79: ; preds = %62
br label %84
80: ; preds = %50
%81 = load i8*, i8** %7
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %79
br label %88
85: ; preds = %2
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0))
br label %88
88: ; preds = %85, %84
%89 = load i32*, i32** %8
%90 = call i32 @fclose(i32* %89)
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"Enter a filename of your choice,\0A \00"
@.str.2 = [34 x i8] c" No filename extension needed: \00"
@.str.3 = [5 x i8] c".csv\00"
@.str.4 = [28 x i8] c"Your filename will be: %s \0A\00"
@.str.5 = [3 x i8] c"a+\00"
@.str.6 = [49 x i8] c"Enter a line of CSV data, separated by commas:\0A \00"
@.str.7 = [25 x i8] c"Could not open file: %s\0A\00"
@str = [34 x i8] c"Usage: csv 'num' : where 'num' is\00"
@str.10 = [45 x i8] c" quantity of csv records you desire.\00"
@str.11 = [39 x i8] c"You did not enter a number. Exiting...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @malloc(i32 255)
%4 = tail call i64 @malloc(i32 50)
%5 = tail call i32 (...) @clrscr()
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = tail call i64 @isdigit(i8 signext %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %39, label %28
15: ; preds = %28
%16 = tail call i32 @atoi(i8* %30)
br label %17
17: ; preds = %15, %7
%18 = phi i32 [ undef, %7 ], [ %16, %15 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i8* @getstring(i32 50)
%22 = tail call i32 @strcat(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%24 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %51, label %26
26: ; preds = %17
%27 = icmp sgt i32 %18, 0
br i1 %27, label %42, label %57
28: ; preds = %12, %34
%29 = phi i64 [ %31, %34 ], [ 0, %12 ]
%30 = load i8*, i8** %8
%31 = add nuw i64 %29, 1
%32 = tail call i64 @strlen(i8* dereferenceable(1) %30)
%33 = icmp ugt i64 %32, %31
br i1 %33, label %34, label %15
34: ; preds = %28
%35 = getelementptr inbounds i8, i8* %30, i64 %31
%36 = load i8, i8* %35
%37 = tail call i64 @isdigit(i8 signext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %28
39: ; preds = %34, %12
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %26, %42
%43 = phi i32 [ %49, %42 ], [ 0, %26 ]
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%45 = tail call i8* @getstring(i32 255)
%46 = tail call i64 @strlen(i8* dereferenceable(1) %45)
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 10, i8* %47
%48 = tail call i32 @fputs(i8* %45, i32* %24)
%49 = add nuw nsw i32 %43, 1
%50 = icmp eq i32 %49, %18
br i1 %50, label %57, label %42
51: ; preds = %17
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %2
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.10, i64 0, i64 0))
unreachable
57: ; preds = %42, %26
%58 = tail call i32 @fclose(i32* %24)
ret i32 0
}