#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 */
int cmp1(char *, char *, int, int, int, int);
int /*<<< orphan*/ get_fields(char **, int, int *, int *, int *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strtok_r(char *, char *, char **);
int field_cmp(char *str1, char *str2, char **fields) {
  char *saveptr1;
  char *saveptr2;
  char as1[strlen(str1) + 1];
  char as2[strlen(str2) + 1];
  strcpy(as1, str1);
  strcpy(as2, str2);
  char *s1 = strtok_r(as1, " ", &saveptr1);
  char *s2 = strtok_r(as2, " ", &saveptr2);
  int n, r, f, d;
  int i = 0;
  while (s1 != NULL && s2 != NULL) {
    get_fields(fields, i, &n, &r, &f, &d);
    int res = cmp1(s1, s2, n, r, f, d);
    if (res)
      return res;
    s1 = strtok_r(NULL, " ", &saveptr1);
    s2 = strtok_r(NULL, " ", &saveptr2);
    i++;
  }
}


x86 assembly (clang, -O0):
<field_cmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x88(%rbp),%rdi
add    $0x1,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x88(%rbp),%rdi
lea    0xe14(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    -0x80(%rbp),%rdi
mov    %rax,-0x50(%rbp)
lea    0xdfc(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x6c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x50(%rbp)
mov    %al,-0x89(%rbp)
je     1239 <field_cmp+0xe9>
cmpq   $0x0,-0x58(%rbp)
setne  %al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    124c <field_cmp+0xfc>
jmp    12e0 <field_cmp+0x190>
mov    -0x20(%rbp),%rdi
mov    -0x6c(%rbp),%esi
lea    -0x5c(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x64(%rbp),%r8
lea    -0x68(%rbp),%r9
call   1040 <get_fields@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x64(%rbp),%r8d
mov    -0x68(%rbp),%r9d
call   1060 <cmp1@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x70(%rbp)
je     12a2 <field_cmp+0x152>
mov    -0x70(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    12e7 <field_cmp+0x197>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd53(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3b(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x58(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1218 <field_cmp+0xc8>
movl   $0x0,-0x74(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<field_cmp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,-0x48(%rbp)
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %rsp,-0x40(%rbp)
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe3f(%rip),%r14
lea    -0x58(%rbp),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strtok_r@plt>
mov    %rax,%r15
lea    -0x50(%rbp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strtok_r@plt>
test   %r15,%r15
je     126f <field_cmp+0x11f>
mov    %rax,%r13
test   %rax,%rax
je     126f <field_cmp+0x11f>
xor    %ebx,%ebx
lea    0xe00(%rip),%r12
mov    -0x48(%rbp),%rdi
mov    %ebx,%esi
lea    -0x38(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x2c(%rbp),%r9
call   1040 <get_fields@plt>
mov    -0x38(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <cmp1@plt>
test   %eax,%eax
jne    126c <field_cmp+0x11c>
xor    %r14d,%r14d
xor    %edi,%edi
mov    %r12,%rsi
lea    -0x58(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %r12,%rsi
lea    -0x50(%rbp),%rdx
call   1070 <strtok_r@plt>
test   %r15,%r15
je     126f <field_cmp+0x11f>
mov    %rax,%r13
add    $0x1,%ebx
test   %rax,%rax
jne    1200 <field_cmp+0xb0>
jmp    126f <field_cmp+0x11f>
mov    %eax,%r14d
mov    -0x40(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @field_cmp(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %10
%27 = alloca i8, i64 %25
store i64 %25, i64* %11
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = zext i32 %30 to i64
%32 = alloca i8, i64 %31
store i64 %31, i64* %12
%33 = load i8*, i8** %5
%34 = call i32 @strcpy(i8* %27, i8* %33)
%35 = load i8*, i8** %6
%36 = call i32 @strcpy(i8* %32, i8* %35)
%37 = call i8* @strtok_r(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %37, i8** %13
%38 = call i8* @strtok_r(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %38, i8** %14
store i32 0, i32* %19
br label %39
39: ; preds = %62, %3
%40 = load i8*, i8** %13
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %14
%44 = icmp ne i8* %43, null
br label %45
45: ; preds = %42, %39
%46 = phi i1 [ false, %39 ], [ %44, %42 ]
br i1 %46, label %47, label %67
47: ; preds = %45
%48 = load i8**, i8*** %7
%49 = load i32, i32* %19
%50 = call i32 @get_fields(i8** %48, i32 %49, i32* %15, i32* %16, i32* %17, i32* %18)
%51 = load i8*, i8** %13
%52 = load i8*, i8** %14
%53 = load i32, i32* %15
%54 = load i32, i32* %16
%55 = load i32, i32* %17
%56 = load i32, i32* %18
%57 = call i32 @cmp1(i8* %51, i8* %52, i32 %53, i32 %54, i32 %55, i32 %56)
store i32 %57, i32* %20
%58 = load i32, i32* %20
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %47
%61 = load i32, i32* %20
store i32 %61, i32* %4
store i32 1, i32* %21
br label %68
62: ; preds = %47
%63 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %63, i8** %13
%64 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %64, i8** %14
%65 = load i32, i32* %19
%66 = add nsw i32 %65, 1
store i32 %66, i32* %19
br label %39
67: ; preds = %45
store i32 0, i32* %21
br label %68
68: ; preds = %67, %60
%69 = load i8*, i8** %10
%70 = load i32, i32* %21
switch i32 %70, label %73 [
i32 0, label %71
i32 1, label %71
]
71: ; preds = %68, %68
%72 = load i32, i32* %4
ret i32 %72
73: ; preds = %68
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @field_cmp(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = bitcast i8** %4 to i8*
%11 = bitcast i8** %5 to i8*
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = tail call i8* @llvm.stacksave()
%16 = alloca i8, i64 %14
%17 = tail call i32 @strlen(i8* %1)
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
%21 = call i32 @strcpy(i8* %16, i8* %0)
%22 = call i32 @strcpy(i8* %20, i8* %1)
%23 = call i8* @strtok_r(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%24 = call i8* @strtok_r(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%25 = bitcast i32* %6 to i8*
%26 = bitcast i32* %7 to i8*
%27 = bitcast i32* %8 to i8*
%28 = bitcast i32* %9 to i8*
%29 = icmp ne i8* %23, null
%30 = icmp ne i8* %24, null
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %32, label %50
32: ; preds = %3, %43
%33 = phi i32 [ %46, %43 ], [ 0, %3 ]
%34 = phi i8* [ %45, %43 ], [ %24, %3 ]
%35 = phi i8* [ %44, %43 ], [ %23, %3 ]
%36 = call i32 @get_fields(i8** %2, i32 %33, i32* %6, i32* %7, i32* %8, i32* %9)
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = load i32, i32* %9
%41 = call i32 @cmp1(i8* %35, i8* %34, i32 %37, i32 %38, i32 %39, i32 %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %32
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%45 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%46 = add nuw nsw i32 %33, 1
%47 = icmp ne i8* %44, null
%48 = icmp ne i8* %45, null
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %32, label %50
50: ; preds = %43, %32, %3
%51 = phi i32 [ undef, %3 ], [ 0, %43 ], [ %41, %32 ]
ret i32 %51
}