#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ parse(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *fr, *fw;
  char *outname;
  size_t newLen, as, ss;
  if (argc < 2) {
    fprintf(stderr, "usage -- %s <file to split>\n", argv[0]);
    return 1;
  }
  if (!(fr = fopen(argv[1], "r"))) {
    fprintf(stderr, "Could not open %s for reading", argv[1]);
    perror("");
    return 1;
  }
  as = strlen(argv[1]) * sizeof(char);
  ss = strlen(".split1stcolumn") * sizeof(char);
  outname = (char *)malloc(as + ss + 1);
  memset(outname, 0, as + ss + 1);
  strcpy(outname, argv[1]);
  strcat(outname, ".split1stcolumn");
  outname[as + ss] = '\0';
  if (!(fw = fopen(outname, "w"))) {
    fprintf(stderr, "Could not open %s for writing", outname);
    perror("");
    close(fr);
    return 1;
  }
  parse(fr, fw);
  fclose(fr);
  fclose(fw);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f8 <main+0x48>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1357 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe16(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    124f <main+0x9f>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xded(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xdde(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1357 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x38(%rbp)
lea    0xdd0(%rip),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
add    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
add    -0x40(%rbp),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1331 <main+0x181>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd44(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd05(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1357 <main+0x1a7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10d0 <parse@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x1,%edi
jg     11e7 <main+0x37>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe29(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%r15d
jmp    1296 <main+0xe6>
mov    0x8(%r13),%rdi
lea    0xe2b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a8 <main+0xf8>
mov    %rax,%r14
mov    0x8(%r13),%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
lea    0xe27(%rip),%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%r12
add    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbp
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1060 <memset@plt>
mov    0x8(%r13),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
lea    0xde4(%rip),%rsi
call   10c0 <strcat@plt>
movb   $0x0,0x0(%rbp,%r12,1)
lea    0xde2(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12d5 <main+0x125>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   10d0 <parse@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r13),%rdx
lea    0xd63(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd54(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%r15d
jmp    1296 <main+0xe6>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    %rbp,%rdx
call   1080 <fprintf@plt>
lea    0xd28(%rip),%rdi
call   10b0 <perror@plt>
mov    %r14,%rdi
call   1070 <close@plt>
mov    $0x1,%r15d
jmp    1296 <main+0xe6>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"usage -- %s <file to split>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Could not open %s for reading\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [16 x i8] c".split1stcolumn\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [30 x i8] c"Could not open %s for writing\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 i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %85
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp ne i32* %24, null
br i1 %25, label %33, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %85
33: ; preds = %20
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 1
store i64 %39, i64* %10
%40 = call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%41 = sext i32 %40 to i64
%42 = mul i64 %41, 1
store i64 %42, i64* %11
%43 = load i64, i64* %10
%44 = load i64, i64* %11
%45 = add i64 %43, %44
%46 = add i64 %45, 1
%47 = call i64 @malloc(i64 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = load i64, i64* %10
%51 = load i64, i64* %11
%52 = add i64 %50, %51
%53 = add i64 %52, 1
%54 = call i32 @memset(i8* %49, i32 0, i64 %53)
%55 = load i8*, i8** %8
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @strcpy(i8* %55, i8* %58)
%60 = load i8*, i8** %8
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%62 = load i8*, i8** %8
%63 = load i64, i64* %10
%64 = load i64, i64* %11
%65 = add i64 %63, %64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %8
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %68, i32** %7
%69 = icmp ne i32* %68, null
br i1 %69, label %77, label %70
70: ; preds = %33
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %8
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%74 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%75 = load i32*, i32** %6
%76 = call i32 @close(i32* %75)
store i32 1, i32* %3
br label %85
77: ; preds = %33
%78 = load i32*, i32** %6
%79 = load i32*, i32** %7
%80 = call i32 @parse(i32* %78, i32* %79)
%81 = load i32*, i32** %6
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %77, %70, %26, %14
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"usage -- %s <file to split>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Could not open %s for reading\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [16 x i8] c".split1stcolumn\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [30 x i8] c"Could not open %s for writing\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %44
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %44
18: ; preds = %8
%19 = load i8*, i8** %9
%20 = tail call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = add nsw i64 %24, 1
%26 = tail call i64 @malloc(i64 %25)
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 @memset(i8* %27, i32 0, i64 %25)
%29 = load i8*, i8** %9
%30 = tail call i32 @strcpy(i8* %27, i8* %29)
%31 = tail call i32 @strcat(i8* %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%32 = getelementptr inbounds i8, i8* %27, i64 %24
store i8 0, i8* %32
%33 = tail call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %40
35: ; preds = %18
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %27)
%38 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%39 = tail call i32 @close(i32* %11)
br label %44
40: ; preds = %18
%41 = tail call i32 @parse(i32* %11, i32* %33)
%42 = tail call i32 @fclose(i32* %11)
%43 = tail call i32 @fclose(i32* %33)
br label %44
44: ; preds = %40, %35, %13, %4
%45 = phi i32 [ 1, %4 ], [ 0, %40 ], [ 1, %35 ], [ 1, %13 ]
ret i32 %45
}