#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 /*<<< orphan*/ do_move(char *, int, int);
int /*<<< orphan*/ fen_board(char *);
int /*<<< orphan*/ init_board();
int /*<<< orphan*/ strip(char *);
char *strstr(char *, char *);
void set_position(char *line) {
  char *ini_moves;
  char *ini_fen;
  char *ini_startpos;
  int from, sz;
  strip(line);
  ini_moves = strstr(line, "moves");
  ini_fen = strstr(line, "fen");
  ini_startpos = strstr(line, "startpos");
  if (ini_startpos) {
    init_board();
  } else if (ini_fen) {
    fen_board(ini_fen + 4);
  }
  if (ini_moves) {
    for (from = 6, sz = 0; ini_moves[from]; from++) {
      if (ini_moves[from] == ' ') {
        if (sz >= 4) {
          do_move(ini_moves, from - sz, sz);
        }
        sz = 0;
      } else {
        sz++;
      }
    }
    if (sz >= 4) {
      do_move(ini_moves, from - sz, sz);
    }
  }
}


x86 assembly (clang, -O0):
<set_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strip@plt>
mov    -0x8(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b8 <set_position+0x68>
mov    $0x0,%al
call   1040 <init_board@plt>
jmp    11d5 <set_position+0x85>
cmpq   $0x0,-0x18(%rbp)
je     11d0 <set_position+0x80>
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
call   1050 <fen_board@plt>
jmp    11d5 <set_position+0x85>
cmpq   $0x0,-0x10(%rbp)
je     127a <set_position+0x12a>
movl   $0x6,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1259 <set_position+0x109>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    123d <set_position+0xed>
cmpl   $0x4,-0x28(%rbp)
jl     1231 <set_position+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
sub    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1030 <do_move@plt>
movl   $0x0,-0x28(%rbp)
jmp    1246 <set_position+0xf6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124b <set_position+0xfb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ee <set_position+0x9e>
cmpl   $0x4,-0x28(%rbp)
jl     1275 <set_position+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
sub    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1030 <do_move@plt>
jmp    127a <set_position+0x12a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_position>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <strip@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
mov    %rax,%r14
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
mov    %rax,%r15
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11a0 <set_position+0x50>
xor    %eax,%eax
call   1040 <init_board@plt>
jmp    11b1 <set_position+0x61>
test   %r15,%r15
je     11b1 <set_position+0x61>
add    $0x4,%r15
mov    %r15,%rdi
call   1050 <fen_board@plt>
test   %r14,%r14
je     120a <set_position+0xba>
xor    %edx,%edx
mov    $0x6,%ebx
jmp    11cd <set_position+0x7d>
nop
xor    %ebp,%ebp
cmp    $0x4,%edx
jge    11e1 <set_position+0x91>
add    $0x1,%rbx
mov    %ebp,%edx
movzbl (%r14,%rbx,1),%eax
cmp    $0x20,%al
je     11c0 <set_position+0x70>
test   %al,%al
je     11ef <set_position+0x9f>
add    $0x1,%edx
mov    %edx,%ebp
jmp    11c7 <set_position+0x77>
mov    %ebx,%esi
sub    %edx,%esi
mov    %r14,%rdi
call   1030 <do_move@plt>
jmp    11c7 <set_position+0x77>
cmp    $0x4,%edx
jl     120a <set_position+0xba>
sub    %edx,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <do_move@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"moves\00"
@.str.1 = [4 x i8] c"fen\00"
@.str.2 = [9 x i8] c"startpos\00"
define void @set_position(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strip(i8* %8)
%10 = load i8*, i8** %2
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %3
%12 = load i8*, i8** %2
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %2
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 (...) @init_board()
br label %28
20: ; preds = %1
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 4
%26 = call i32 @fen_board(i8* %25)
br label %27
27: ; preds = %23, %20
br label %28
28: ; preds = %27, %18
%29 = load i8*, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %76
31: ; preds = %28
store i32 6, i32* %6
store i32 0, i32* %7
br label %32
32: ; preds = %62, %31
%33 = load i8*, i8** %3
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = icmp ne i8 %37, 0
br i1 %38, label %39, label %65
39: ; preds = %32
%40 = load i8*, i8** %3
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 32
br i1 %46, label %47, label %58
47: ; preds = %39
%48 = load i32, i32* %7
%49 = icmp sge i32 %48, 4
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = sub nsw i32 %52, %53
%55 = load i32, i32* %7
%56 = call i32 @do_move(i8* %51, i32 %54, i32 %55)
br label %57
57: ; preds = %50, %47
store i32 0, i32* %7
br label %61
58: ; preds = %39
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %61
61: ; preds = %58, %57
br label %62
62: ; preds = %61
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %32
65: ; preds = %32
%66 = load i32, i32* %7
%67 = icmp sge i32 %66, 4
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load i8*, i8** %3
%70 = load i32, i32* %6
%71 = load i32, i32* %7
%72 = sub nsw i32 %70, %71
%73 = load i32, i32* %7
%74 = call i32 @do_move(i8* %69, i32 %72, i32 %73)
br label %75
75: ; preds = %68, %65
br label %76
76: ; preds = %75, %28
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"moves\00"
@.str.1 = [4 x i8] c"fen\00"
@.str.2 = [9 x i8] c"startpos\00"
define void @set_position(i8* %0) {
%2 = tail call i32 @strip(i8* %0)
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i32 (...) @init_board()
br label %14
9: ; preds = %1
%10 = icmp eq i8* %4, null
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %4, i64 4
%13 = tail call i32 @fen_board(i8* %12)
br label %14
14: ; preds = %9, %11, %7
%15 = icmp eq i8* %3, null
br i1 %15, label %38, label %16
16: ; preds = %14, %29
%17 = phi i64 [ %31, %29 ], [ 6, %14 ]
%18 = phi i32 [ %30, %29 ], [ 0, %14 ]
%19 = getelementptr inbounds i8, i8* %3, i64 %17
%20 = load i8, i8* %19
switch i8 %20, label %27 [
i8 0, label %32
i8 32, label %21
]
21: ; preds = %16
%22 = icmp sgt i32 %18, 3
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = trunc i64 %17 to i32
%25 = sub nsw i32 %24, %18
%26 = tail call i32 @do_move(i8* %3, i32 %25, i32 %18)
br label %29
27: ; preds = %16
%28 = add nsw i32 %18, 1
br label %29
29: ; preds = %21, %23, %27
%30 = phi i32 [ %28, %27 ], [ 0, %23 ], [ 0, %21 ]
%31 = add nuw i64 %17, 1
br label %16
32: ; preds = %16
%33 = icmp sgt i32 %18, 3
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = trunc i64 %17 to i32
%36 = sub nsw i32 %35, %18
%37 = tail call i32 @do_move(i8* %3, i32 %36, i32 %18)
br label %38
38: ; preds = %32, %34, %14
ret void
}