#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 *strchr(char *, char);
int getMoveFromLine(char *line, char *nextMove) {
  char *moveStart = strchr(line, '[');
  char *moveEnd = strchr(line, ']');
  if (moveStart == NULL || moveEnd == NULL) {
    return -1;
  }
  int moveLength = moveEnd - moveStart - 1;
  if (moveLength != 2) {
    return -2;
  }
  nextMove[0] = *(moveStart + 1);
  nextMove[1] = *(moveStart + 2);
  nextMove[2] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<getMoveFromLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115a <getMoveFromLine+0x4a>
cmpq   $0x0,-0x28(%rbp)
jne    1166 <getMoveFromLine+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <getMoveFromLine+0xa8>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
je     118e <getMoveFromLine+0x7e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b8 <getMoveFromLine+0xa8>
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMoveFromLine>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x5b,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    $0xffffffff,%ecx
test   %r15,%r15
je     116b <getMoveFromLine+0x5b>
test   %rax,%rax
je     116b <getMoveFromLine+0x5b>
mov    %r15d,%ecx
not    %ecx
add    %ecx,%eax
mov    $0xfffffffe,%ecx
cmp    $0x2,%eax
jne    116b <getMoveFromLine+0x5b>
mov    0x1(%r15),%al
mov    %al,(%r14)
mov    0x2(%r15),%al
mov    %al,0x1(%r14)
movb   $0x0,0x2(%r14)
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @getMoveFromLine(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 91)
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @strchr(i8* %11, i8 signext 93)
store i8* %12, i8** %7
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15, %2
store i32 -1, i32* %3
br label %43
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = load i8*, i8** %6
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = sub nsw i64 %24, 1
%26 = trunc i64 %25 to i32
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 -2, i32* %3
br label %43
30: ; preds = %19
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 %33, i8* %35
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 %38, i8* %40
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 2
store i8 0, i8* %42
store i32 0, i32* %3
br label %43
43: ; preds = %30, %29, %18
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @getMoveFromLine(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 93)
%5 = icmp eq i8* %3, null
%6 = icmp eq i8* %4, null
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %3 to i64
%11 = xor i64 %10, -1
%12 = add i64 %9, %11
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = getelementptr inbounds i8, i8* %3, i64 1
%17 = load i8, i8* %16
store i8 %17, i8* %1
%18 = getelementptr inbounds i8, i8* %3, i64 2
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %19, i8* %20
%21 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %21
br label %22
22: ; preds = %15, %8, %2
%23 = phi i32 [ -1, %2 ], [ 0, %15 ], [ -2, %8 ]
ret i32 %23
}