#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 EXIT_SUCCESS;
char *csv_field(int);
char *csv_getline(int /*<<< orphan*/);
int csv_nfield();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char *line;
  while ((line = csv_getline(stdin)) != NULL) {
    printf("%s\n", line);
    for (int i = 0; i < csv_nfield(); i++)
      printf("field[%2d] = %s\n", i, csv_field(i));
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1030 <csv_getline@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11da <main+0x9a>
mov    -0x18(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <csv_nfield@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11d5 <main+0x95>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <csv_field@plt>
mov    -0x24(%rbp),%esi
mov    %rax,%rdx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <main+0x4b>
jmp    1156 <main+0x16>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e8d(%rip),%r14
mov    (%r14),%edi
call   1030 <csv_getline@plt>
test   %rax,%rax
je     11d6 <main+0x86>
lea    0xe91(%rip),%rbx
jmp    118d <main+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1030 <csv_getline@plt>
test   %rax,%rax
je     11d6 <main+0x86>
mov    %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <csv_nfield@plt>
test   %eax,%eax
jle    1180 <main+0x30>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1070 <csv_field@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   1060 <csv_nfield@plt>
cmp    %eax,%ebp
jl     11b0 <main+0x60>
jmp    1180 <main+0x30>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [17 x i8] c"field[%2d] = %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %27, %2
%9 = load i32, i32* @stdin
%10 = call i8* @csv_getline(i32 %9)
store i8* %10, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load i8*, i8** %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %7
br label %15
15: ; preds = %24, %12
%16 = load i32, i32* %7
%17 = call i32 (...) @csv_nfield()
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %7
%21 = load i32, i32* %7
%22 = call i8* @csv_field(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %15
27: ; preds = %15
br label %8
28: ; preds = %8
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [17 x i8] c"field[%2d] = %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @stdin
%4 = tail call i8* @csv_getline(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %10
6: ; preds = %15, %10
%7 = load i32, i32* @stdin
%8 = tail call i8* @csv_getline(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %2, %6
%11 = phi i8* [ %8, %6 ], [ %4, %2 ]
%12 = tail call i32 @puts(i8* %11)
%13 = tail call i32 (...) @csv_nfield()
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %10, %15
%16 = phi i32 [ %19, %15 ], [ 0, %10 ]
%17 = tail call i8* @csv_field(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %17)
%19 = add nuw nsw i32 %16, 1
%20 = tail call i32 (...) @csv_nfield()
%21 = icmp slt i32 %19, %20
br i1 %21, label %15, label %6
22: ; preds = %6, %2
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}