#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ split_field(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strdup(char *);
size_t strlen(char *);
void parse(char *filename) {
  char *line = 0;
  char *readName, *tmp;
  size_t n;
  int pos;
  FILE *in, *out;
  char *outname;
  if (!(in = fopen(filename, "r"))) {
    fprintf(stderr, "Could not open %s for reading", filename);
    perror("");
    return;
  }
  outname = (char *)malloc(sizeof(char) *
                           (strlen(filename) + strlen(".split1stcolumn") + 1));
  memset(outname, 0,
         sizeof(char) * (strlen(filename) + strlen(".split1stcolumn") + 1));
  sprintf(outname, "%s%s", filename, ".split1stcolumn");
  outname[strlen(filename) + strlen(".split1stcolumn")] = 0;
  if (!(out = fopen(outname, "w"))) {
    fprintf(stderr, "Could not open %s for writing", outname);
    perror("");
    close(in);
    return;
  }
  tmp = 0;
  while ((!feof(in)) && (getline(&line, &n, in) != -1)) {
    if (tmp) {
      free(tmp);
      tmp = 0;
    }
    tmp = strdup(line);
    char *found = strchr(line, '\t');
    pos = (found - line);
    split_field(tmp, pos);
    fputs(tmp, out);
  }
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    125f <parse+0x5f>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb9(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xdca(%rip),%rdi
call   10f0 <perror@plt>
jmp    1438 <parse+0x238>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x78(%rbp)
lea    0xdad(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x68(%rbp)
lea    0xd6f(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd4c(%rip),%rsi
lea    0xd35(%rip),%rcx
call   1110 <sprintf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x60(%rbp)
lea    0xd14(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rcx
mov    %rax,%rdx
mov    -0x58(%rbp),%rax
add    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1374 <parse+0x174>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xce2(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xcbe(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <close@plt>
jmp    1438 <parse+0x238>
movq   $0x0,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   10c0 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x79(%rbp)
jne    13af <parse+0x1af>
mov    -0x38(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1100 <getline@plt>
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    13bf <parse+0x1bf>
jmp    1426 <parse+0x226>
cmpq   $0x0,-0x20(%rbp)
je     13db <parse+0x1db>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1120 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <split_field@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <fputs@plt>
jmp    137c <parse+0x17c>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0xddf(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1346 <parse+0x146>
mov    %rax,%r13
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x10(%rax),%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x10(%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xdcf(%rip),%rsi
lea    0xdb8(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1110 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movb   $0x0,0xf(%rax,%rbx,1)
lea    0xdae(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1378 <parse+0x178>
mov    %rax,%r14
mov    %r13,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
je     12c6 <parse+0xc6>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    1320 <parse+0x120>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1120 <strdup@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
sub    %ebp,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <split_field@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fputs@plt>
mov    %r13,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    12a7 <parse+0xa7>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1100 <getline@plt>
cmp    $0xffffffff,%eax
je     12a7 <parse+0xa7>
test   %rbx,%rbx
je     12e0 <parse+0xe0>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12e0 <parse+0xe0>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xcac(%rip),%rsi
mov    %r14,%rdx
call   10b0 <fprintf@plt>
lea    0xcba(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10f0 <perror@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
lea    0xcaf(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
lea    0xc88(%rip),%rdi
call   10f0 <perror@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <close@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not open %s for reading\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [16 x i8] c".split1stcolumn\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [30 x i8] c"Could not open %s for writing\00"
define void @parse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %20, label %15
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %2
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %97
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = call i64 @strlen(i8* %21)
%23 = call i64 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = add i64 %22, %23
%25 = add i64 %24, 1
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = load i8*, i8** %2
%32 = call i64 @strlen(i8* %31)
%33 = call i64 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%34 = add i64 %32, %33
%35 = add i64 %34, 1
%36 = mul i64 1, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @memset(i8* %30, i32 0, i32 %37)
%39 = load i8*, i8** %10
%40 = load i8*, i8** %2
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%42 = load i8*, i8** %10
%43 = load i8*, i8** %2
%44 = call i64 @strlen(i8* %43)
%45 = call i64 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%46 = add i64 %44, %45
%47 = getelementptr inbounds i8, i8* %42, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %10
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %49, i32** %9
%50 = icmp ne i32* %49, null
br i1 %50, label %58, label %51
51: ; preds = %20
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %10
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %53)
%55 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32*, i32** %8
%57 = call i32 @close(i32* %56)
br label %97
58: ; preds = %20
store i8* null, i8** %5
br label %59
59: ; preds = %75, %58
%60 = load i32*, i32** %8
%61 = call i32 @feof(i32* %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i32*, i32** %8
%65 = call i32 @getline(i8** %3, i64* %6, i32* %64)
%66 = icmp ne i32 %65, -1
br label %67
67: ; preds = %63, %59
%68 = phi i1 [ false, %59 ], [ %66, %63 ]
br i1 %68, label %69, label %92
69: ; preds = %67
%70 = load i8*, i8** %5
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i8*, i8** %5
%74 = call i32 @free(i8* %73)
store i8* null, i8** %5
br label %75
75: ; preds = %72, %69
%76 = load i8*, i8** %3
%77 = call i8* @strdup(i8* %76)
store i8* %77, i8** %5
%78 = load i8*, i8** %3
%79 = call i8* @strchr(i8* %78, i8 signext 9)
store i8* %79, i8** %11
%80 = load i8*, i8** %11
%81 = load i8*, i8** %3
%82 = ptrtoint i8* %80 to i64
%83 = ptrtoint i8* %81 to i64
%84 = sub i64 %82, %83
%85 = trunc i64 %84 to i32
store i32 %85, i32* %7
%86 = load i8*, i8** %5
%87 = load i32, i32* %7
%88 = call i32 @split_field(i8* %86, i32 %87)
%89 = load i8*, i8** %5
%90 = load i32*, i32** %9
%91 = call i32 @fputs(i8* %89, i32* %90)
br label %59
92: ; preds = %67
%93 = load i32*, i32** %8
%94 = call i32 @fclose(i32* %93)
%95 = load i32*, i32** %9
%96 = call i32 @fclose(i32* %95)
br label %97
97: ; preds = %92, %51, %15
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Could not open %s for reading\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [16 x i8] c".split1stcolumn\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [30 x i8] c"Could not open %s for writing\00"
define void @parse(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
%6 = tail call i32* @fopen(i8* %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 = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %59
12: ; preds = %1
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = trunc i64 %13 to i32
%15 = add i32 %14, 16
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%19 = trunc i64 %18 to i32
%20 = add i32 %19, 16
%21 = tail call i32 @memset(i8* %17, i32 0, i32 %20)
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%24 = add i64 %23, 15
%25 = getelementptr inbounds i8, i8* %17, i64 %24
store i8 0, i8* %25
%26 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %12
%29 = call i32 @feof(i32* %6)
%30 = icmp eq i32 %29, 0
br i1 %30, label %36, label %56
31: ; preds = %12
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%34 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @close(i32* %6)
br label %59
36: ; preds = %28, %44
%37 = phi i8* [ %46, %44 ], [ null, %28 ]
%38 = call i32 @getline(i8** %2, i64* %3, i32* %6)
%39 = icmp eq i32 %38, -1
br i1 %39, label %56, label %40
40: ; preds = %36
%41 = icmp eq i8* %37, null
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = call i32 @free(i8* %37)
br label %44
44: ; preds = %42, %40
%45 = load i8*, i8** %2
%46 = call i8* @strdup(i8* %45)
%47 = call i8* @strchr(i8* dereferenceable(1) %45, i8 signext 9)
%48 = ptrtoint i8* %47 to i64
%49 = ptrtoint i8* %45 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = call i32 @split_field(i8* %46, i32 %51)
%53 = call i32 @fputs(i8* %46, i32* %26)
%54 = call i32 @feof(i32* %6)
%55 = icmp eq i32 %54, 0
br i1 %55, label %36, label %56
56: ; preds = %36, %44, %28
%57 = call i32 @fclose(i32* %6)
%58 = call i32 @fclose(i32* %26)
br label %59
59: ; preds = %56, %31, %8
ret void
}