#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 const *strdup(char const *);
char *strtok(char *, char *);
const char *getfield(char *line, int num) {
  char *tmp = strdup(line);
  const char *tok;
  for (tok = strtok(tmp, " "); tok && *tok; tok = strtok(NULL, " ")) {
    if (--num < 0) {
      return strdup(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
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     1170 <getfield+0x50>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1180 <getfield+0x60>
jmp    11c2 <getfield+0xa2>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a4 <getfield+0x84>
mov    -0x28(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ca <getfield+0xaa>
jmp    11a9 <getfield+0x89>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe4c(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1150 <getfield+0x30>
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
call   1040 <strdup@plt>
lea    0xece(%rip),%rsi
mov    %rax,%rdi
call   1030 <strtok@plt>
test   %rax,%rax
je     116b <getfield+0x4b>
add    $0x1,%ebx
lea    0xeb7(%rip),%r14
nopl   0x0(%rax)
cmpb   $0x0,(%rax)
je     116b <getfield+0x4b>
add    $0xffffffff,%ebx
test   %ebx,%ebx
jle    1175 <getfield+0x55>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
jne    1150 <getfield+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strdup@plt>

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

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