#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  size_t rm_eo;
  size_t rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int /*<<< orphan*/ REG_EXTENDED;
int atoi(char *);
int /*<<< orphan*/ exit_with(char *, int);
void *malloc(int);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                           int /*<<< orphan*/);
char toupper(char);
int do_move_parse(char *line, int *from, int *to, int *n) {
  char regex[] = "^([A-z])[[:space:]]+([A-z])[[:space:]]+([1-9][0-9]*)$";
  static int initialized = 0;
  static regex_t *regex_comp;
  static regmatch_t *reg_matches;
  if (!initialized) {
    if (!(regex_comp = malloc(sizeof(regex_t)))) {
      exit_with("malloc error", 1);
    }
    if (!(reg_matches = malloc(sizeof(regmatch_t) * 4))) {
      exit_with("malloc error", 1);
    }
    if (regcomp(regex_comp, regex, REG_EXTENDED)) {
      exit_with("regex compilation error", 0);
    }
    initialized = 1;
  }
  if (!regexec(regex_comp, line, 4, reg_matches, 0)) {
    line[reg_matches[1].rm_eo] = '\0';
    *from = toupper(line[reg_matches[1].rm_so]) - 'A';
    line[reg_matches[2].rm_eo] = '\0';
    *to = toupper(line[reg_matches[2].rm_so]) - 'A';
    line[reg_matches[3].rm_eo] = '\0';
    *n = atoi(&line[reg_matches[3].rm_so]);
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<do_move_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x36,%edx
call   1050 <memcpy@plt>
cmpl   $0x0,0x2ebc(%rip)
jne    123d <do_move_parse+0xcd>
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,0x2ead(%rip)
cmp    $0x0,%rax
jne    11d6 <do_move_parse+0x66>
lea    0xe6a(%rip),%rdi
mov    $0x1,%esi
call   1090 <exit_with@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,0x2e89(%rip)
cmp    $0x0,%rax
jne    1202 <do_move_parse+0x92>
lea    0xe3e(%rip),%rdi
mov    $0x1,%esi
call   1090 <exit_with@plt>
mov    0x2e5f(%rip),%rdi
lea    -0x60(%rbp),%rsi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
call   1040 <regcomp@plt>
cmp    $0x0,%rax
je     1233 <do_move_parse+0xc3>
lea    0xe17(%rip),%rdi
xor    %esi,%esi
call   1090 <exit_with@plt>
movl   $0x1,0x2e23(%rip)
mov    0x2e24(%rip),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e21(%rip),%rcx
mov    $0x4,%edx
xor    %r8d,%r8d
call   1070 <regexec@plt>
cmp    $0x0,%eax
jne    130e <do_move_parse+0x19e>
mov    -0x10(%rbp),%rax
mov    0x2e00(%rip),%rcx
mov    0x10(%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x2ded(%rip),%rcx
mov    0x18(%rcx),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
movsbl %al,%ecx
sub    $0x41,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x2dc9(%rip),%rcx
mov    0x20(%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x2db6(%rip),%rcx
mov    0x28(%rcx),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
movsbl %al,%ecx
sub    $0x41,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x2d92(%rip),%rcx
mov    0x30(%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    0x2d7f(%rip),%rax
add    0x38(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1315 <do_move_parse+0x1a5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_move_parse>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe85(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x24292a5d392d30,%rax
mov    %rax,0x2e(%rsp)
cmpb   $0x0,0x2ea7(%rip)
jne    1237 <do_move_parse+0xd7>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,0x2e98(%rip)
test   %rax,%rax
jne    11de <do_move_parse+0x7e>
lea    0xe62(%rip),%rdi
mov    $0x1,%esi
call   1080 <exit_with@plt>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,0x2e79(%rip)
test   %rax,%rax
jne    1205 <do_move_parse+0xa5>
lea    0xe3b(%rip),%rdi
mov    $0x1,%esi
call   1080 <exit_with@plt>
mov    0x2e54(%rip),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rsi
call   1040 <regcomp@plt>
test   %rax,%rax
je     1230 <do_move_parse+0xd0>
lea    0xe1a(%rip),%rdi
xor    %esi,%esi
call   1080 <exit_with@plt>
movb   $0x1,0x2e21(%rip)
mov    0x2e22(%rip),%rdi
mov    0x2e23(%rip),%rcx
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %r8d,%r8d
call   1060 <regexec@plt>
test   %eax,%eax
jne    12c9 <do_move_parse+0x169>
mov    0x2e06(%rip),%rax
mov    0x10(%rax),%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    0x18(%rax),%rax
movsbl (%rbx,%rax,1),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
add    $0xffffffbf,%eax
mov    %eax,(%r12)
mov    0x2de0(%rip),%rax
mov    0x20(%rax),%rcx
movb   $0x0,(%rbx,%rcx,1)
mov    0x28(%rax),%rax
movsbl (%rbx,%rax,1),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
add    $0xffffffbf,%eax
mov    %eax,(%r15)
mov    0x2dbb(%rip),%rax
mov    0x30(%rax),%rcx
movb   $0x0,(%rbx,%rcx,1)
add    0x38(%rax),%rbx
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@__const.do_move_parse.regex = [54 x i8] c"^([A-z])[[:space:]]+([A-z])[[:space:]]+([1-9][0-9]*)$\00"
@do_move_parse.initialized = internal global i32 0
@do_move_parse.regex_comp = internal global i32* null
@do_move_parse.reg_matches = internal global %struct.TYPE_3__* null
@.str = [13 x i8] c"malloc error\00"
@REG_EXTENDED = global i32 0
@.str.1 = [24 x i8] c"regex compilation error\00"
define i32 @do_move_parse(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [54 x i8]
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = bitcast [54 x i8]* %10 to i8*
%12 = load i32, i32* @do_move_parse.initialized
%13 = icmp ne i32 %12, 0
br i1 %13, label %35, label %14
14: ; preds = %4
%15 = call i8* @malloc(i32 4)
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** @do_move_parse.regex_comp
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
br label %20
20: ; preds = %18, %14
%21 = call i8* @malloc(i32 64)
%22 = bitcast i8* %21 to %struct.TYPE_3__*
store %struct.TYPE_3__* %22, %struct.TYPE_3__** @do_move_parse.reg_matches
%23 = icmp ne %struct.TYPE_3__* %22, null
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
br label %26
26: ; preds = %24, %20
%27 = load i32*, i32** @do_move_parse.regex_comp
%28 = getelementptr inbounds [54 x i8], [54 x i8]* %10, i64 0, i64 0
%29 = load i32, i32* @REG_EXTENDED
%30 = call i64 @regcomp(i32* %27, i8* %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @exit_with(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %34
34: ; preds = %32, %26
store i32 1, i32* @do_move_parse.initialized
br label %35
35: ; preds = %34, %4
%36 = load i32*, i32** @do_move_parse.regex_comp
%37 = load i8*, i8** %6
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%39 = call i32 @regexec(i32* %36, i8* %37, i32 4, %struct.TYPE_3__* %38, i32 0)
%40 = icmp ne i32 %39, 0
br i1 %40, label %90, label %41
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i64 1
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %44, i32 0, i32 0
%46 = load i64, i64* %45
%47 = getelementptr inbounds i8, i8* %42, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %6
%49 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i64 1
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = getelementptr inbounds i8, i8* %48, i64 %52
%54 = load i8, i8* %53
%55 = call signext i8 @toupper(i8 signext %54)
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %56, 65
%58 = load i32*, i32** %7
store i32 %57, i32* %58
%59 = load i8*, i8** %6
%60 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%61 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %60, i64 2
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds i8, i8* %59, i64 %63
store i8 0, i8* %64
%65 = load i8*, i8** %6
%66 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%67 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %66, i64 2
%68 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %67, i32 0, i32 1
%69 = load i64, i64* %68
%70 = getelementptr inbounds i8, i8* %65, i64 %69
%71 = load i8, i8* %70
%72 = call signext i8 @toupper(i8 signext %71)
%73 = sext i8 %72 to i32
%74 = sub nsw i32 %73, 65
%75 = load i32*, i32** %8
store i32 %74, i32* %75
%76 = load i8*, i8** %6
%77 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%78 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %77, i64 3
%79 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %78, i32 0, i32 0
%80 = load i64, i64* %79
%81 = getelementptr inbounds i8, i8* %76, i64 %80
store i8 0, i8* %81
%82 = load i8*, i8** %6
%83 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%84 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %83, i64 3
%85 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %84, i32 0, i32 1
%86 = load i64, i64* %85
%87 = getelementptr inbounds i8, i8* %82, i64 %86
%88 = call i32 @atoi(i8* %87)
%89 = load i32*, i32** %9
store i32 %88, i32* %89
store i32 1, i32* %5
br label %91
90: ; preds = %35
store i32 0, i32* %5
br label %91
91: ; preds = %90, %41
%92 = load i32, i32* %5
ret i32 %92
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@__const.do_move_parse.regex = [54 x i8] c"^([A-z])[[:space:]]+([A-z])[[:space:]]+([1-9][0-9]*)$\00"
@do_move_parse.initialized = internal unnamed_addr global i1 false
@do_move_parse.regex_comp = internal unnamed_addr global i32* null
@do_move_parse.reg_matches = internal unnamed_addr global %struct.TYPE_3__* null
@.str = [13 x i8] c"malloc error\00"
@REG_EXTENDED = global i32 0
@.str.1 = [24 x i8] c"regex compilation error\00"
define i32 @do_move_parse(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [54 x i8]
%6 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 0
%7 = load i1, i1* @do_move_parse.initialized
br i1 %7, label %26, label %8
8: ; preds = %4
%9 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
store i8* %9, i8** bitcast (i32** @do_move_parse.regex_comp to i8**)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
br label %13
13: ; preds = %11, %8
%14 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
store i8* %14, i8** bitcast (%struct.TYPE_3__** @do_move_parse.reg_matches to i8**)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @exit_with(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1)
br label %18
18: ; preds = %16, %13
%19 = load i32*, i32** @do_move_parse.regex_comp
%20 = load i32, i32* @REG_EXTENDED
%21 = call i64 @regcomp(i32* %19, i8* %6, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @exit_with(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %25
25: ; preds = %23, %18
store i1 true, i1* @do_move_parse.initialized
br label %26
26: ; preds = %25, %4
%27 = load i32*, i32** @do_move_parse.regex_comp
%28 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%29 = call i32 @regexec(i32* %27, i8* %0, i32 4, %struct.TYPE_3__* %28, i32 0)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %62
31: ; preds = %26
%32 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i64 1, i32 0
%34 = load i64, i64* %33
%35 = getelementptr inbounds i8, i8* %0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i64 1, i32 1
%37 = load i64, i64* %36
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
%40 = call signext i8 @toupper(i8 signext %39)
%41 = sext i8 %40 to i32
%42 = add nsw i32 %41, -65
store i32 %42, i32* %1
%43 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i64 2, i32 0
%45 = load i64, i64* %44
%46 = getelementptr inbounds i8, i8* %0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i64 2, i32 1
%48 = load i64, i64* %47
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = call signext i8 @toupper(i8 signext %50)
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, -65
store i32 %53, i32* %2
%54 = load %struct.TYPE_3__*, %struct.TYPE_3__** @do_move_parse.reg_matches
%55 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %54, i64 3, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds i8, i8* %0, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %54, i64 3, i32 1
%59 = load i64, i64* %58
%60 = getelementptr inbounds i8, i8* %0, i64 %59
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %3
br label %62
62: ; preds = %26, %31
%63 = phi i32 [ 1, %31 ], [ 0, %26 ]
ret i32 %63
}