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


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    11bd <getField+0x9d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    119f <getField+0x7f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <getField+0xa5>
jmp    11a4 <getField+0x84>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe53(%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     1173 <getField+0x53>
lea    0xebc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,(%rax)
je     1173 <getField+0x53>
mov    %rax,%rcx
add    $0xffffffff,%ebx
je     1175 <getField+0x55>
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <strtok@plt>
mov    $0x0,%ecx
test   %rax,%rax
jne    1150 <getField+0x30>
jmp    1175 <getField+0x55>
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*
%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 = %29, %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 %31
22: ; preds = %20
%23 = load i32, i32* %5
%24 = add nsw i32 %23, -1
store i32 %24, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = load i8*, i8** %7
store i8* %27, i8** %3
br label %32
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %7
br label %12
31: ; preds = %20
store i8* null, i8** %3
br label %32
32: ; preds = %31, %26
%33 = load i8*, i8** %3
ret i8* %33
}

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