#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 */

/* Variables and functions */
int atoi(char *);
char *column2pipe(char *, char *, int, char);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buffer[1024];
  char input[1024];
  char delimiter;
  int number_fields_to_pipe;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s number_fields_to_pipe [delimiter]\n", argv[0]);
    exit(1);
  }
  number_fields_to_pipe = atoi(argv[1]);
  if (argc == 3)
    delimiter = *argv[2];
  else
    delimiter = '|';
  while (get_line(input, stdin)) {
    printf("%s\n",
           column2pipe(buffer, input, number_fields_to_pipe, delimiter));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a9 <main+0x49>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11db <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x811(%rbp)
jmp    11e2 <main+0x82>
movb   $0x7c,-0x811(%rbp)
jmp    11e7 <main+0x87>
lea    -0x810(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     123a <main+0xda>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x818(%rbp),%edx
movsbl -0x811(%rbp),%ecx
call   1080 <column2pipe@plt>
mov    %rax,%rsi
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
jmp    11e7 <main+0x87>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1210 <main+0xb0>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    $0x7c,%r14b
cmp    $0x3,%ebp
jne    119a <main+0x3a>
mov    0x10(%rbx),%rax
mov    (%rax),%r14b
mov    0x2e47(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11fc <main+0x9c>
movsbl %r14b,%ebp
lea    0x400(%rsp),%r14
mov    %rsp,%rbx
lea    0xe65(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1080 <column2pipe@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xddd(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s number_fields_to_pipe [delimiter]\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
store i8 %30, i8* %8
br label %32
31: ; preds = %19
store i8 124, i8* %8
br label %32
32: ; preds = %31, %26
br label %33
33: ; preds = %38, %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i64 @get_line(i8* %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %33
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %9
%42 = load i8, i8* %8
%43 = call i8* @column2pipe(i8* %39, i8* %40, i32 %41, i8 signext %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %33
45: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s number_fields_to_pipe [delimiter]\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp eq i32 %0, 3
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
br label %22
22: ; preds = %13, %18
%23 = phi i8 [ %21, %18 ], [ 124, %13 ]
%24 = load i32, i32* @stdin
%25 = call i64 @get_line(i8* %6, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %22, %27
%28 = call i8* @column2pipe(i8* %5, i8* %6, i32 %16, i8 signext %23)
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stdin
%31 = call i64 @get_line(i8* %6, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %27
33: ; preds = %27, %22
ret i32 0
}