#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*/ byLine;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  FILE *input_file, *out_file;
  const char *mode = "r";
  char outFilename[] = "output.csv";
  char ch;
  char byLine[72];
  input_file = fopen("input.csv", mode);
  if (input_file == NULL) {
    fprintf(stderr, "Can't open input file, input.csv!\n");
    exit(1);
  }
  out_file = fopen(outFilename, "w");
  if (out_file == NULL) {
    fprintf(stderr, "Can't open output file, output.csv %s!\n", outFilename);
    exit(1);
  }
  printf("Prolog format output of %s file are :\n", outFilename);
  int commaCount = 0;
  char par = ')';
  char period = '.';
  char paranPeriod[3] = ").";
  char control = '\n';
  int carReturn = '\r';
  while (fgets(byLine, sizeof(byLine), input_file) != NULL) {
    char *ptr = byLine;
    int adjustedLength = strlen(byLine) + strlen(paranPeriod);
    int testLength = strlen(byLine);
    int insertLocation = testLength - 1;
    while (*ptr != '\0') {
      if (*ptr == ',' && commaCount == 0) {
        *ptr = '(';
        commaCount++;
      }
      ptr++;
    }
    char *output = (char *)malloc(adjustedLength + 1);
    strncpy(output, byLine, insertLocation);
    output[insertLocation] = '\0';
    strcat(output, paranPeriod);
    strcat(output, byLine + insertLocation);
    printf("%s", output);
    fputs(output, out_file);
    commaCount = 0;
    free(output);
  }
  fclose(input_file);
  fclose(out_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe27(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe1e(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xe1b(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe13(%rip),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123c <main+0x7c>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x2b(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1280 <main+0xc0>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    -0x2b(%rbp),%rdx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x2b(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x84(%rbp)
movb   $0x29,-0x85(%rbp)
movb   $0x2e,-0x86(%rbp)
mov    0xddc(%rip),%ax
mov    %ax,-0x89(%rbp)
mov    0xdd1(%rip),%al
mov    %al,-0x87(%rbp)
movb   $0xa,-0x8a(%rbp)
movl   $0xd,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x48,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     144e <main+0x28e>
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xb4(%rbp)
lea    -0x89(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x9c(%rbp)
lea    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13a6 <main+0x1e6>
mov    -0x98(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    138f <main+0x1cf>
cmpl   $0x0,-0x84(%rbp)
jne    138f <main+0x1cf>
mov    -0x98(%rbp),%rax
movb   $0x28,(%rax)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1343 <main+0x183>
mov    -0x9c(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0xb0(%rbp),%rax
movslq -0xa4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xb0(%rbp),%rdi
lea    -0x89(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0xb0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
movslq -0xa4(%rbp),%rax
add    %rax,%rsi
call   10d0 <strcat@plt>
mov    -0xb0(%rbp),%rsi
lea    0xc70(%rip),%rdi
call   1070 <printf@plt>
mov    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <fputs@plt>
movl   $0x0,-0x84(%rbp)
mov    -0xb0(%rbp),%rdi
call   1030 <free@plt>
jmp    12d3 <main+0x113>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movabs $0x632e74757074756f,%rax
74 2e 63
mov    %rax,0x18(%rsp)
movl   $0x767363,0x1f(%rsp)
lea    0xe21(%rip),%rdi
lea    0xe0d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1368 <main+0x1a8>
lea    0xe2d(%rip),%rsi
lea    0x18(%rsp),%rdi
call   10c0 <fopen@plt>
mov    %rax,0x28(%rsp)
test   %rax,%rax
je     1389 <main+0x1c9>
lea    0xe38(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1070 <printf@plt>
movb   $0x0,0xe(%rsp)
movw   $0x2e29,0xc(%rsp)
lea    0x30(%rsp),%rdi
mov    $0x48,%esi
mov    0x10(%rsp),%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1343 <main+0x183>
lea    0x30(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    12e6 <main+0x126>
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r13,1),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <strcat@plt>
lea    (%rsp,%rbp,1),%rsi
add    $0x30,%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
lea    0xddc(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    0x28(%rsp),%rsi
call   1080 <fputs@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x48,%esi
mov    0x10(%rsp),%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1343 <main+0x183>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbp
add    $0xffffffffffffffff,%rbp
mov    0x30(%rsp),%dl
test   %dl,%dl
je     1270 <main+0xb0>
xor    %ecx,%ecx
lea    0x31(%rsp),%rax
jmp    132f <main+0x16f>
movzbl (%rax),%edx
add    $0x1,%rax
test   %dl,%dl
je     1270 <main+0xb0>
cmp    $0x2c,%dl
jne    1320 <main+0x160>
test   %ecx,%ecx
jne    1320 <main+0x160>
movb   $0x28,-0x1(%rax)
mov    $0x1,%ecx
jmp    1320 <main+0x160>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    0x28(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
lea    0xc9f(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    0xca3(%rip),%rsi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@__const.main.outFilename = [11 x i8] c"output.csv\00"
@.str.1 = [10 x i8] c"input.csv\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Can't open input file, input.csv!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"Can't open output file, output.csv %s!\0A\00"
@.str.5 = [39 x i8] c"Prolog format output of %s file are :\0A\00"
@__const.main.paranPeriod = [3 x i8] c").\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [11 x i8]
%6 = alloca i8
%7 = alloca [72 x i8]
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca [3 x i8]
%12 = alloca i8
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
%19 = bitcast [11 x i8]* %5 to i8*
%20 = load i8*, i8** %4
%21 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32* %21, i32** %2
%22 = load i32*, i32** %2
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %0
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %0
%29 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %3
%31 = load i32*, i32** %3
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %39)
store i32 0, i32* %8
store i8 41, i8* %9
store i8 46, i8* %10
%41 = bitcast [3 x i8]* %11 to i8*
store i8 10, i8* %12
store i32 13, i32* %13
br label %42
42: ; preds = %78, %38
%43 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
%44 = load i32*, i32** %2
%45 = call i32* @fgets(i8* %43, i32 72, i32* %44)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %107
47: ; preds = %42
%48 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
store i8* %48, i8** %14
%49 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = add nsw i32 %50, %52
store i32 %53, i32* %15
%54 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
store i32 %55, i32* %16
%56 = load i32, i32* %16
%57 = sub nsw i32 %56, 1
store i32 %57, i32* %17
br label %58
58: ; preds = %75, %47
%59 = load i8*, i8** %14
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %78
63: ; preds = %58
%64 = load i8*, i8** %14
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 44
br i1 %67, label %68, label %75
68: ; preds = %63
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %68
%72 = load i8*, i8** %14
store i8 40, i8* %72
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %75
75: ; preds = %71, %68, %63
%76 = load i8*, i8** %14
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %14
br label %58
78: ; preds = %58
%79 = load i32, i32* %15
%80 = add nsw i32 %79, 1
%81 = call i64 @malloc(i32 %80)
%82 = inttoptr i64 %81 to i8*
store i8* %82, i8** %18
%83 = load i8*, i8** %18
%84 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
%85 = load i32, i32* %17
%86 = call i32 @strncpy(i8* %83, i8* %84, i32 %85)
%87 = load i8*, i8** %18
%88 = load i32, i32* %17
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
store i8 0, i8* %90
%91 = load i8*, i8** %18
%92 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%93 = call i32 @strcat(i8* %91, i8* %92)
%94 = load i8*, i8** %18
%95 = getelementptr inbounds [72 x i8], [72 x i8]* %7, i64 0, i64 0
%96 = load i32, i32* %17
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = call i32 @strcat(i8* %94, i8* %98)
%100 = load i8*, i8** %18
%101 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %100)
%102 = load i8*, i8** %18
%103 = load i32*, i32** %3
%104 = call i32 @fputs(i8* %102, i32* %103)
store i32 0, i32* %8
%105 = load i8*, i8** %18
%106 = call i32 @free(i8* %105)
br label %42
107: ; preds = %42
%108 = load i32*, i32** %2
%109 = call i32 @fclose(i32* %108)
%110 = load i32*, i32** %3
%111 = call i32 @fclose(i32* %110)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@__const.main.outFilename = [11 x i8] c"output.csv\00"
@.str.1 = [10 x i8] c"input.csv\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Can't open input file, input.csv!\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"Can't open output file, output.csv %s!\0A\00"
@.str.5 = [39 x i8] c"Prolog format output of %s file are :\0A\00"
@__const.main.paranPeriod = [3 x i8] c").\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = alloca [72 x i8]
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [72 x i8], [72 x i8]* %2, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%22 = call i32* @fgets(i8* %5, i32 72, i32* %6)
%23 = icmp eq i32* %22, null
br i1 %23, label %60, label %24
24: ; preds = %19, %44
%25 = call i32 @strlen(i8* %5)
%26 = call i32 @strlen(i8* %21)
%27 = call i32 @strlen(i8* %5)
%28 = add nsw i32 %27, -1
%29 = load i8, i8* %5
%30 = icmp eq i8 %29, 0
br i1 %30, label %44, label %31
31: ; preds = %24, %39
%32 = phi i8 [ %42, %39 ], [ %29, %24 ]
%33 = phi i32 [ %40, %39 ], [ 0, %24 ]
%34 = phi i8* [ %41, %39 ], [ %5, %24 ]
%35 = icmp eq i8 %32, 44
%36 = icmp eq i32 %33, 0
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %38, label %39
38: ; preds = %31
store i8 40, i8* %34
br label %39
39: ; preds = %38, %31
%40 = phi i32 [ 1, %38 ], [ %33, %31 ]
%41 = getelementptr inbounds i8, i8* %34, i64 1
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %31
44: ; preds = %39, %24
%45 = add i32 %25, 1
%46 = add i32 %45, %26
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
%49 = call i32 @strncpy(i8* %48, i8* %5, i32 %28)
%50 = sext i32 %28 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = call i32 @strcat(i8* %48, i8* %21)
%53 = getelementptr inbounds [72 x i8], [72 x i8]* %2, i64 0, i64 %50
%54 = call i32 @strcat(i8* %48, i8* %53)
%55 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%56 = call i32 @fputs(i8* %48, i32* %13)
%57 = call i32 @free(i8* %48)
%58 = call i32* @fgets(i8* %5, i32 72, i32* %6)
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %24
60: ; preds = %44, %19
%61 = call i32 @fclose(i32* %6)
%62 = call i32 @fclose(i32* %13)
ret i32 0
}