#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__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strtok(char *, char *);
int parse_three(char *line, char *field1, char *field2, char *field3) {
  char *ptr;
  int i, n, rc;
  i = 0;
  rc = 0;
  ptr = strtok(line, "\t\n");
  while (ptr != NULL) {
    i++;
    switch (i) {
    case 1:
      n = (int)strlen(ptr);
      if (n > 2048 - 1)
        n = 2048 - 1;
      strncpy(field1, ptr, (size_t)n);
      field1[n] = (char)'\0';
      rc += 1;
      break;
    case 2:
      n = (int)strlen(ptr);
      if (n > 2048 - 1)
        n = 2048 - 1;
      strncpy(field2, ptr, (size_t)n);
      field2[n] = (char)'\0';
      rc += 2;
      break;
    case 3:
      n = (int)strlen(ptr);
      if (n > 2048 - 1)
        n = 2048 - 1;
      strncpy(field3, ptr, (size_t)n);
      field3[n] = (char)'\0';
      rc += 4;
      break;
    default:
      rc = 0;
    }
    ptr = strtok(NULL, "\t\n");
  }
  if (rc == 7)
    return (0);
  else
    return (1);
}


x86 assembly (clang, -O0):
<parse_three>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12b5 <parse_three+0x185>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     11b4 <parse_three+0x84>
jmp    1192 <parse_three+0x62>
mov    -0x40(%rbp),%eax
sub    $0x2,%eax
je     11ff <parse_three+0xcf>
jmp    11a3 <parse_three+0x73>
mov    -0x40(%rbp),%eax
sub    $0x3,%eax
je     124a <parse_three+0x11a>
jmp    1295 <parse_three+0x165>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x7ff,-0x38(%rbp)
jle    11d4 <parse_three+0xa4>
movl   $0x7ff,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    129c <parse_three+0x16c>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x7ff,-0x38(%rbp)
jle    121f <parse_three+0xef>
movl   $0x7ff,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
jmp    129c <parse_three+0x16c>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x7ff,-0x38(%rbp)
jle    126a <parse_three+0x13a>
movl   $0x7ff,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x3c(%rbp)
jmp    129c <parse_three+0x16c>
movl   $0x0,-0x3c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd59(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    116a <parse_three+0x3a>
cmpl   $0x7,-0x3c(%rbp)
jne    12cb <parse_three+0x19b>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <parse_three+0x1a2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_three>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rsi,(%rsp)
lea    0xead(%rip),%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     1269 <parse_three+0x139>
mov    %rax,%rbx
xor    %r15d,%r15d
lea    0xe92(%rip),%r13
xor    %r14d,%r14d
jmp    11db <parse_three+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x7ff,%eax
movslq %eax,%rbp
mov    $0x7ff,%eax
cmovge %rax,%rbp
mov    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
add    %r12,%rbp
mov    $0x4,%eax
add    %eax,%r15d
movb   $0x0,0x0(%rbp)
mov    %r15d,%ebp
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
mov    %rax,%rbx
add    $0x1,%r14d
mov    %ebp,%r15d
test   %rax,%rax
je     126b <parse_three+0x13b>
cmp    $0x2,%r14d
je     1180 <parse_three+0x50>
cmp    $0x1,%r14d
je     1230 <parse_three+0x100>
mov    $0x0,%ebp
test   %r14d,%r14d
jne    11be <parse_three+0x8e>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x7ff,%eax
movslq %eax,%rbp
mov    $0x7ff,%eax
cmovge %rax,%rbp
mov    (%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
add    %r12,%rbp
mov    $0x1,%eax
jmp    11b4 <parse_three+0x84>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x7ff,%eax
movslq %eax,%rbp
mov    $0x7ff,%eax
cmovge %rax,%rbp
mov    0x8(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
add    %r12,%rbp
mov    $0x2,%eax
jmp    11b4 <parse_three+0x84>
xor    %ebp,%ebp
xor    %eax,%eax
cmp    $0x7,%ebp
setne  %al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\09\0A\00"
define i32 @parse_three(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 0, i32* %11
store i32 0, i32* %13
%14 = load i8*, i8** %6
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %10
br label %16
16: ; preds = %81, %4
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %83
19: ; preds = %16
%20 = load i32, i32* %11
%21 = add nsw i32 %20, 1
store i32 %21, i32* %11
%22 = load i32, i32* %11
switch i32 %22, label %80 [
i32 1, label %23
i32 2, label %42
i32 3, label %61
]
23: ; preds = %19
%24 = load i8*, i8** %10
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp sgt i32 %27, 2047
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 2047, i32* %12
br label %30
30: ; preds = %29, %23
%31 = load i8*, i8** %7
%32 = load i8*, i8** %10
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = call i32 @strncpy(i8* %31, i8* %32, i64 %34)
%36 = load i8*, i8** %7
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %13
%41 = add nsw i32 %40, 1
store i32 %41, i32* %13
br label %81
42: ; preds = %19
%43 = load i8*, i8** %10
%44 = call i64 @strlen(i8* %43)
%45 = trunc i64 %44 to i32
store i32 %45, i32* %12
%46 = load i32, i32* %12
%47 = icmp sgt i32 %46, 2047
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 2047, i32* %12
br label %49
49: ; preds = %48, %42
%50 = load i8*, i8** %8
%51 = load i8*, i8** %10
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = call i32 @strncpy(i8* %50, i8* %51, i64 %53)
%55 = load i8*, i8** %8
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 2
store i32 %60, i32* %13
br label %81
61: ; preds = %19
%62 = load i8*, i8** %10
%63 = call i64 @strlen(i8* %62)
%64 = trunc i64 %63 to i32
store i32 %64, i32* %12
%65 = load i32, i32* %12
%66 = icmp sgt i32 %65, 2047
br i1 %66, label %67, label %68
67: ; preds = %61
store i32 2047, i32* %12
br label %68
68: ; preds = %67, %61
%69 = load i8*, i8** %9
%70 = load i8*, i8** %10
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = call i32 @strncpy(i8* %69, i8* %70, i64 %72)
%74 = load i8*, i8** %9
%75 = load i32, i32* %12
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 0, i8* %77
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 4
store i32 %79, i32* %13
br label %81
80: ; preds = %19
store i32 0, i32* %13
br label %81
81: ; preds = %80, %68, %49, %30
%82 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %82, i8** %10
br label %16
83: ; preds = %16
%84 = load i32, i32* %13
%85 = icmp eq i32 %84, 7
br i1 %85, label %86, label %87
86: ; preds = %83
store i32 0, i32* %5
br label %88
87: ; preds = %83
store i32 1, i32* %5
br label %88
88: ; preds = %87, %86
%89 = load i32, i32* %5
ret i32 %89
}

LLVM IR (-O2):
@.str = [3 x i8] c"\09\0A\00"
define i32 @parse_three(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %47, label %7
7: ; preds = %4, %43
%8 = phi i32 [ %44, %43 ], [ 0, %4 ]
%9 = phi i32 [ %11, %43 ], [ 0, %4 ]
%10 = phi i8* [ %45, %43 ], [ %5, %4 ]
%11 = add nuw nsw i32 %9, 1
switch i32 %9, label %43 [
i32 0, label %12
i32 1, label %21
i32 2, label %30
]
12: ; preds = %7
%13 = tail call i64 @strlen(i8* %10)
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %14, 2047
%16 = shl i64 %13, 32
%17 = ashr exact i64 %16, 32
%18 = select i1 %15, i64 %17, i64 2047
%19 = tail call i32 @strncpy(i8* %1, i8* %10, i64 %18)
%20 = getelementptr inbounds i8, i8* %1, i64 %18
br label %39
21: ; preds = %7
%22 = tail call i64 @strlen(i8* %10)
%23 = trunc i64 %22 to i32
%24 = icmp slt i32 %23, 2047
%25 = shl i64 %22, 32
%26 = ashr exact i64 %25, 32
%27 = select i1 %24, i64 %26, i64 2047
%28 = tail call i32 @strncpy(i8* %2, i8* %10, i64 %27)
%29 = getelementptr inbounds i8, i8* %2, i64 %27
br label %39
30: ; preds = %7
%31 = tail call i64 @strlen(i8* %10)
%32 = trunc i64 %31 to i32
%33 = icmp slt i32 %32, 2047
%34 = shl i64 %31, 32
%35 = ashr exact i64 %34, 32
%36 = select i1 %33, i64 %35, i64 2047
%37 = tail call i32 @strncpy(i8* %3, i8* %10, i64 %36)
%38 = getelementptr inbounds i8, i8* %3, i64 %36
br label %39
39: ; preds = %12, %21, %30
%40 = phi i8* [ %38, %30 ], [ %29, %21 ], [ %20, %12 ]
%41 = phi i32 [ 4, %30 ], [ 2, %21 ], [ 1, %12 ]
store i8 0, i8* %40
%42 = add nsw i32 %8, %41
br label %43
43: ; preds = %39, %7
%44 = phi i32 [ 0, %7 ], [ %42, %39 ]
%45 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %7
47: ; preds = %43, %4
%48 = phi i32 [ 0, %4 ], [ %44, %43 ]
%49 = icmp ne i32 %48, 7
%50 = zext i1 %49 to i32
ret i32 %50
}