#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ strcmp(char *, char const *);
char *strtok(char *, char *);
int get_field_number(const char *field_name, const char *buffer, int len) {
  int llen;
  char *line;
  char *token;
  for (llen = 0; llen < len; llen++)
    if (buffer[llen] == '\n')
      break;
  line = (char *)malloc(llen);
  memcpy(line, buffer, llen);
  line[llen] = '\0';
  for (token = strtok(line, ","), llen = 0; token;
       token = strtok(NULL, ","), llen++) {
    if (strcmp(token, field_name) == 0) {
      return llen;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_field_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1193 <get_field_number+0x53>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1180 <get_field_number+0x40>
jmp    1193 <get_field_number+0x53>
jmp    1185 <get_field_number+0x45>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115a <get_field_number+0x1a>
mov    -0x20(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     122a <get_field_number+0xea>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1203 <get_field_number+0xc3>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1231 <get_field_number+0xf1>
jmp    1208 <get_field_number+0xc8>
xor    %eax,%eax
mov    %eax,%edi
lea    0xded(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <get_field_number+0x96>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_field_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
test   %edx,%edx
jle    1174 <get_field_number+0x34>
mov    %edx,%eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0xa,0x0(%rbp,%rbx,1)
je     1176 <get_field_number+0x36>
add    $0x1,%rbx
cmp    %rbx,%rax
jne    1160 <get_field_number+0x20>
mov    %eax,%ebx
jmp    1176 <get_field_number+0x36>
xor    %ebx,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
lea    0xe65(%rip),%rsi
mov    %r15,%rdi
call   1060 <strtok@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     11e7 <get_field_number+0xa7>
xor    %ebp,%ebp
lea    0xe49(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e4 <get_field_number+0xa4>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11c0 <get_field_number+0x80>
jmp    11e7 <get_field_number+0xa7>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @get_field_number(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %25, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %15
br label %28
24: ; preds = %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %11
28: ; preds = %23, %11
%29 = load i32, i32* %8
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = call i32 @memcpy(i8* %32, i8* %33, i32 %34)
%36 = load i8*, i8** %9
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %9
%41 = call i8* @strtok(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %10
store i32 0, i32* %8
br label %42
42: ; preds = %53, %28
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %57
45: ; preds = %42
%46 = load i8*, i8** %10
%47 = load i8*, i8** %5
%48 = call i64 @strcmp(i8* %46, i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = load i32, i32* %8
store i32 %51, i32* %4
br label %58
52: ; preds = %45
br label %53
53: ; preds = %52
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %54, i8** %10
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %42
57: ; preds = %42
store i32 -1, i32* %4
br label %58
58: ; preds = %57, %50
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @get_field_number(i8* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %13, %12 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %17, label %7
15: ; preds = %7
%16 = trunc i64 %8 to i32
br label %17
17: ; preds = %12, %15, %3
%18 = phi i32 [ 0, %3 ], [ %16, %15 ], [ %2, %12 ]
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @memcpy(i8* %20, i8* %1, i32 %18)
%22 = zext i32 %18 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = tail call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %35, label %26
26: ; preds = %17, %31
%27 = phi i8* [ %32, %31 ], [ %24, %17 ]
%28 = phi i32 [ %33, %31 ], [ 0, %17 ]
%29 = tail call i64 @strcmp(i8* %27, i8* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = add nuw nsw i32 %28, 1
%34 = icmp eq i8* %32, null
br i1 %34, label %35, label %26
35: ; preds = %26, %31, %17
%36 = phi i32 [ -1, %17 ], [ -1, %31 ], [ %28, %26 ]
ret i32 %36
}