#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long,
                           unsigned long);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void _lex_col_val(char *line_buf, size_t line_buf_len, size_t *lex_pos,
                  char *val_buf, size_t val_buf_len) {
  size_t maxlen, len = 0;
  unsigned char done = 0;
  char *c;
  while (!done && len < line_buf_len) {
    c = (line_buf + *lex_pos + len++);
    switch (*c) {
    case '\0':
    case '\n':
    case ',': {
      done = 1;
    }
    default:
      break;
    }
  }
  if (len > val_buf_len) {
    fprintf(stderr, "len > val_buf_len (%lu > %lu)\n", (unsigned long)len,
            (unsigned long)val_buf_len);
    maxlen = val_buf_len;
  } else {
    maxlen = len;
  }
  if (maxlen) {
    strncpy(val_buf, line_buf + *lex_pos, maxlen);
  }
  if (val_buf_len) {
    val_buf[val_buf_len - 1] = '\0';
  }
  *lex_pos += len;
}


x86 assembly (clang, -O0):
<_lex_col_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movb   $0x0,-0x39(%rbp)
xor    %eax,%eax
cmpb   $0x0,-0x39(%rbp)
mov    %al,-0x49(%rbp)
jne    1165 <_lex_col_val+0x45>
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
setb   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1175 <_lex_col_val+0x55>
jmp    11e0 <_lex_col_val+0xc0>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
add    %rcx,%rax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x50(%rbp)
test   %eax,%eax
je     11d2 <_lex_col_val+0xb2>
jmp    11b0 <_lex_col_val+0x90>
mov    -0x50(%rbp),%eax
sub    $0xa,%eax
je     11d2 <_lex_col_val+0xb2>
jmp    11c1 <_lex_col_val+0xa1>
mov    -0x50(%rbp),%eax
sub    $0x2c,%eax
jne    11d6 <_lex_col_val+0xb6>
jmp    11d2 <_lex_col_val+0xb2>
movb   $0x1,-0x39(%rbp)
jmp    11db <_lex_col_val+0xbb>
jmp    1148 <_lex_col_val+0x28>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    1218 <_lex_col_val+0xf8>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdfa(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1220 <_lex_col_val+0x100>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1243 <_lex_col_val+0x123>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
add    (%rax),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncpy@plt>
cmpq   $0x0,-0x28(%rbp)
je     125e <_lex_col_val+0x13e>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_lex_col_val>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdx,%r14
test   %rsi,%rsi
je     11d0 <_lex_col_val+0xb0>
mov    %rdi,%r12
mov    (%r14),%rax
add    %rdi,%rax
xor    %edi,%edi
movabs $0x100000000401,%rdx
jmp    1169 <_lex_col_val+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rcx),%rdi
cmp    %rsi,%rdi
jae    117b <_lex_col_val+0x5b>
mov    %rdi,%rcx
movsbl (%rax,%rdi,1),%edi
cmp    $0x2c,%edi
ja     1160 <_lex_col_val+0x40>
bt     %rdi,%rdx
jae    1160 <_lex_col_val+0x40>
lea    0x1(%rcx),%r13
mov    %r13,%rdx
cmp    %rbx,%rcx
jb     11aa <_lex_col_val+0x8a>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    %rbx,%rdx
test   %rbx,%rbx
je     11c3 <_lex_col_val+0xa3>
add    (%r14),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
test   %rbx,%rbx
je     11c3 <_lex_col_val+0xa3>
movb   $0x0,-0x1(%rbx,%r15,1)
add    %r13,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %r13d,%r13d
test   %rbx,%rbx
jne    11bd <_lex_col_val+0x9d>
jmp    11c3 <_lex_col_val+0xa3>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"len > val_buf_len (%lu > %lu)\0A\00"
define void @_lex_col_val(i8* %0, i64 %1, i64* %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8
%14 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64* %2, i64** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
store i64 0, i64* %12
store i8 0, i8* %13
br label %15
15: ; preds = %37, %5
%16 = load i8, i8* %13
%17 = icmp ne i8 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i64, i64* %12
%20 = load i64, i64* %7
%21 = icmp ult i64 %19, %20
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ false, %15 ], [ %21, %18 ]
br i1 %23, label %24, label %38
24: ; preds = %22
%25 = load i8*, i8** %6
%26 = load i64*, i64** %8
%27 = load i64, i64* %26
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i64, i64* %12
%30 = add i64 %29, 1
store i64 %30, i64* %12
%31 = getelementptr inbounds i8, i8* %28, i64 %29
store i8* %31, i8** %14
%32 = load i8*, i8** %14
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %36 [
i32 0, label %35
i32 10, label %35
i32 44, label %35
]
35: ; preds = %24, %24, %24
store i8 1, i8* %13
br label %36
36: ; preds = %24, %35
br label %37
37: ; preds = %36
br label %15
38: ; preds = %22
%39 = load i64, i64* %12
%40 = load i64, i64* %10
%41 = icmp ugt i64 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i64, i64* %12
%45 = load i64, i64* %10
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %44, i64 %45)
%47 = load i64, i64* %10
store i64 %47, i64* %11
br label %50
48: ; preds = %38
%49 = load i64, i64* %12
store i64 %49, i64* %11
br label %50
50: ; preds = %48, %42
%51 = load i64, i64* %11
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i8*, i8** %9
%55 = load i8*, i8** %6
%56 = load i64*, i64** %8
%57 = load i64, i64* %56
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i64, i64* %11
%60 = call i32 @strncpy(i8* %54, i8* %58, i64 %59)
br label %61
61: ; preds = %53, %50
%62 = load i64, i64* %10
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = load i8*, i8** %9
%66 = load i64, i64* %10
%67 = sub i64 %66, 1
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
br label %69
69: ; preds = %64, %61
%70 = load i64, i64* %12
%71 = load i64*, i64** %8
%72 = load i64, i64* %71
%73 = add i64 %72, %70
store i64 %73, i64* %71
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"len > val_buf_len (%lu > %lu)\0A\00"
define void @_lex_col_val(i8* %0, i64 %1, i64* nocapture %2, i8* %3, i64 %4) {
%6 = icmp eq i64 %1, 0
br i1 %6, label %29, label %7
7: ; preds = %5
%8 = load i64, i64* %2
%9 = getelementptr inbounds i8, i8* %0, i64 %8
br label %10
10: ; preds = %7, %16
%11 = phi i64 [ 0, %7 ], [ %12, %16 ]
%12 = add nuw i64 %11, 1
%13 = getelementptr inbounds i8, i8* %9, i64 %11
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %16 [
i32 0, label %18
i32 10, label %18
i32 44, label %18
]
16: ; preds = %10
%17 = icmp ult i64 %12, %1
br i1 %17, label %10, label %18
18: ; preds = %10, %10, %10, %16
%19 = icmp ult i64 %11, %4
br i1 %19, label %24, label %20
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %12, i64 %4)
%23 = icmp eq i64 %4, 0
br i1 %23, label %35, label %24
24: ; preds = %18, %20
%25 = phi i64 [ %4, %20 ], [ %12, %18 ]
%26 = load i64, i64* %2
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = tail call i32 @strncpy(i8* %3, i8* %27, i64 %25)
br label %29
29: ; preds = %5, %24
%30 = phi i64 [ %12, %24 ], [ 0, %5 ]
%31 = icmp eq i64 %4, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = add i64 %4, -1
%34 = getelementptr inbounds i8, i8* %3, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %20, %32, %29
%36 = phi i64 [ %30, %32 ], [ %30, %29 ], [ %12, %20 ]
%37 = load i64, i64* %2
%38 = add i64 %37, %36
store i64 %38, i64* %2
ret void
}