#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 /*<<< orphan*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
char *malloc(int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlen(char *);
void ProcessCSV(FILE *fpin, FILE *fpout, const char *enc_tag,
                const char *d1_tag, const char *d2_tag) {
  char *buff = malloc(2048);
  char *line;
  line = fgets(buff, 2048, fpin);
  while (line != NULL) {
    char *comma = strchr(line, ',');
    if (!comma) {
      fprintf(stderr, "[ERROR] Malformed CSV line in input file %s\n\n", line);
      exit(1);
    }
    *comma = 0;
    comma++;
    comma[strlen(comma) - 1] = 0;
    fprintf(stderr, "%s\n", line);
    fprintf(stderr, "%s\n", comma + 1);
    fprintf(fpout, "\t<%s>\n\t\t<%s>%s</%s><%s>%s</%s>\n\t</%s>\n", enc_tag,
            d1_tag, line, d1_tag, d2_tag, comma, d2_tag, enc_tag);
    line = fgets(line, 2048, fpin);
  }
}


x86 assembly (clang, -O0):
<ProcessCSV>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12bf <ProcessCSV+0x15f>
mov    -0x40(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11ef <ProcessCSV+0x8f>
mov    0x2e10(%rip),%rax
movslq (%rax),%rdi
mov    -0x40(%rbp),%rdx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2db6(%rip),%rax
movslq (%rax),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d9a(%rip),%rax
movslq (%rax),%rdi
mov    -0x48(%rbp),%rdx
add    $0x1,%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rbx
mov    -0x48(%rbp),%r11
mov    -0x30(%rbp),%r10
mov    -0x20(%rbp),%rax
lea    0xda8(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
mov    %rax,-0x40(%rbp)
jmp    11a1 <ProcessCSV+0x41>
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<ProcessCSV>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbp
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,%rdi
mov    $0x800,%esi
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     125f <ProcessCSV+0xff>
mov    %rax,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     126e <ProcessCSV+0x10e>
mov    %rax,%r12
movb   $0x0,(%rax)
lea    0x1(%rax),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,(%rax,%r12,1)
mov    0x2dfa(%rip),%r14
movslq (%r14),%rdi
lea    0xe3e(%rip),%rbx
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
movslq (%r14),%rdi
add    $0x2,%r12
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x20(%rsp),%rdi
lea    0xe15(%rip),%rsi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
mov    %rbp,%r8
mov    %rcx,%r9
xor    %eax,%eax
push   %r15
mov    0x18(%rsp),%rbx
push   %rbx
push   %r13
push   %rbx
call   1060 <fprintf@plt>
add    $0x20,%rsp
mov    %rbp,%rdi
mov    $0x800,%esi
mov    0x18(%rsp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11b0 <ProcessCSV+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6b(%rip),%rax
movslq (%rax),%rdi
lea    0xd81(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"[ERROR] Malformed CSV line in input file %s\0A\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [39 x i8] c"\09<%s>\0A\09\09<%s>%s</%s><%s>%s</%s>\0A\09</%s>\0A\00"
define void @ProcessCSV(i32* %0, i32* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%14 = call i8* @malloc(i32 2048)
store i8* %14, i8** %11
%15 = load i8*, i8** %11
%16 = load i32*, i32** %6
%17 = call i8* @fgets(i8* %15, i32 2048, i32* %16)
store i8* %17, i8** %12
br label %18
18: ; preds = %33, %5
%19 = load i8*, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %67
21: ; preds = %18
%22 = load i8*, i8** %12
%23 = call i8* @strchr(i8* %22, i8 signext 44)
store i8* %23, i8** %13
%24 = load i8*, i8** %13
%25 = icmp ne i8* %24, null
br i1 %25, label %33, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8*, i8** %12
%31 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = load i8*, i8** %13
store i8 0, i8* %34
%35 = load i8*, i8** %13
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %13
%37 = load i8*, i8** %13
%38 = load i8*, i8** %13
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* @stderr
%44 = sext i32 %43 to i64
%45 = inttoptr i64 %44 to i32*
%46 = load i8*, i8** %12
%47 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @stderr
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i32*
%51 = load i8*, i8** %13
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = load i32*, i32** %7
%55 = load i8*, i8** %8
%56 = load i8*, i8** %9
%57 = load i8*, i8** %12
%58 = load i8*, i8** %9
%59 = load i8*, i8** %10
%60 = load i8*, i8** %13
%61 = load i8*, i8** %10
%62 = load i8*, i8** %8
%63 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %55, i8* %56, i8* %57, i8* %58, i8* %59, i8* %60, i8* %61, i8* %62)
%64 = load i8*, i8** %12
%65 = load i32*, i32** %6
%66 = call i8* @fgets(i8* %64, i32 2048, i32* %65)
store i8* %66, i8** %12
br label %18
67: ; preds = %18
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"[ERROR] Malformed CSV line in input file %s\0A\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [39 x i8] c"\09<%s>\0A\09\09<%s>%s</%s><%s>%s</%s>\0A\09</%s>\0A\00"
define void @ProcessCSV(i32* nocapture %0, i32* nocapture %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%7 = tail call i8* @fgets(i8* %6, i32 2048, i32* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %37, label %9
9: ; preds = %5, %19
%10 = phi i8* [ %35, %19 ], [ %7, %5 ]
%11 = tail call i8* @strchr(i8* %10, i8 signext 44)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %10)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9
store i8 0, i8* %11
%20 = getelementptr inbounds i8, i8* %11, i64 1
%21 = tail call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = load i32, i32* @stderr
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i32*
%28 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%29 = load i32, i32* @stderr
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i32*
%32 = getelementptr inbounds i8, i8* %11, i64 2
%33 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %3, i8* %10, i8* %3, i8* %4, i8* %20, i8* %4, i8* %2)
%35 = tail call i8* @fgets(i8* %10, i32 2048, i32* %0)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %9
37: ; preds = %19, %5
ret void
}