#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 */
char *strtok(char *, char *);
const char *getfield(char *line, int num) {
  const char *tok;
  for (tok = strtok(line, ","); tok && *tok; tok = strtok(NULL, ",\n")) {
    if (!--num)
      return tok;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed6(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     1153 <getfield+0x43>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1163 <getfield+0x53>
jmp    11a0 <getfield+0x90>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1182 <getfield+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <getfield+0x98>
jmp    1187 <getfield+0x77>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe70(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1133 <getfield+0x23>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfield>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0xee3(%rip),%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     1153 <getfield+0x43>
lea    0xed4(%rip),%r14
xchg   %ax,%ax
cmpb   $0x0,(%rax)
je     1153 <getfield+0x43>
mov    %rax,%rcx
add    $0xffffffff,%ebx
je     1155 <getfield+0x45>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
mov    $0x0,%ecx
test   %rax,%rax
jne    1130 <getfield+0x20>
jmp    1155 <getfield+0x45>
xor    %ecx,%ecx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [3 x i8] c",\0A\00"
define i8* @getfield(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
br label %9
9: ; preds = %26, %2
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %28
19: ; preds = %17
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %29
25: ; preds = %19
br label %26
26: ; preds = %25
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %6
br label %9
28: ; preds = %17
store i8* null, i8** %3
br label %29
29: ; preds = %28, %23
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [3 x i8] c",\0A\00"
define i8* @getfield(i8* %0, i32 %1) {
%3 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2, %13
%6 = phi i8* [ %14, %13 ], [ %3, %2 ]
%7 = phi i32 [ %11, %13 ], [ %1, %2 ]
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = add nsw i32 %7, -1
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %5
16: ; preds = %10, %13, %5, %2
%17 = phi i8* [ null, %2 ], [ null, %5 ], [ null, %13 ], [ %6, %10 ]
ret i8* %17
}