#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 atoi(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int extractMoves(char *line) {
  char work[60];
  strcpy(work, line);
  int moves = 0;
  char *partOfLine;
  partOfLine = strtok(work, ",");
  int i = 0;
  while (partOfLine != NULL) {
    switch (i % 3) {
    case 2:
      moves = atoi(partOfLine);
      break;
    default:
      break;
    }
    partOfLine = strtok(NULL, ",");
    i++;
  }
  return moves;
}


x86 assembly (clang, -O0):
<extractMoves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     11dd <extractMoves+0xad>
movslq -0x64(%rbp),%rcx
mov    %ecx,%eax
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
sub    $0x2,%eax
jne    11b6 <extractMoves+0x86>
jmp    11a5 <extractMoves+0x75>
mov    -0x60(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x54(%rbp)
jmp    11bb <extractMoves+0x8b>
jmp    11bb <extractMoves+0x8b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3a(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x60(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    116b <extractMoves+0x3b>
mov    -0x54(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractMoves>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11b3 <extractMoves+0x83>
xor    %ebp,%ebp
mov    $0x2,%ebx
mov    $0xaaaaaaab,%r12d
lea    0xe8e(%rip),%r15
xor    %r14d,%r14d
jmp    1195 <extractMoves+0x65>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebp
add    $0xffffffff,%ebx
test   %rax,%rax
je     11b6 <extractMoves+0x86>
mov    %ebp,%ecx
imul   %r12,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
add    %ebx,%ecx
jne    1180 <extractMoves+0x50>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
jmp    1180 <extractMoves+0x50>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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