#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 *next_word(char *);
int strlen(char *);
int assemble_mov(char *line) {
  char *regs = next_word(line);
  int lreg, rreg;
  if (strlen(regs) >= 3 && regs[1] == ',') {
    lreg = 0x3 & (regs[0] - 'A');
    rreg = 0x3 & (regs[2] - 'A');
  } else
    return -1;
  return 0x30 | (lreg << 2) | rreg;
}


x86 assembly (clang, -O0):
<assemble_mov>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <next_word@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     1182 <assemble_mov+0x62>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2c,%eax
jne    1182 <assemble_mov+0x62>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
sub    $0x41,%eax
and    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x41,%eax
and    $0x3,%eax
mov    %eax,-0x20(%rbp)
jmp    118e <assemble_mov+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <assemble_mov+0x7d>
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
or     $0x30,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assemble_mov>:
push   %rbx
call   1030 <next_word@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x3,%ecx
jl     115c <assemble_mov+0x3c>
cmpb   $0x2c,0x1(%rbx)
jne    115c <assemble_mov+0x3c>
mov    (%rbx),%al
mov    0x2(%rbx),%cl
add    $0xff,%cl
and    $0x3,%cl
shl    $0x2,%al
add    $0xc,%al
and    $0xc,%al
or     %cl,%al
or     $0x30,%al
movzbl %al,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @assemble_mov(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @next_word(i8* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp sge i32 %10, 3
br i1 %11, label %12, label %31
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 44
br i1 %17, label %18, label %31
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 65
%24 = and i32 3, %23
store i32 %24, i32* %5
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 65
%30 = and i32 3, %29
store i32 %30, i32* %6
br label %32
31: ; preds = %12, %1
store i32 -1, i32* %2
br label %38
32: ; preds = %18
%33 = load i32, i32* %5
%34 = shl i32 %33, 2
%35 = or i32 48, %34
%36 = load i32, i32* %6
%37 = or i32 %35, %36
store i32 %37, i32* %2
br label %38
38: ; preds = %32, %31
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @assemble_mov(i8* %0) {
%2 = tail call i8* @next_word(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 2
br i1 %4, label %5, label %21
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %2, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 44
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i8, i8* %2
%11 = getelementptr inbounds i8, i8* %2, i64 2
%12 = load i8, i8* %11
%13 = add i8 %12, 3
%14 = and i8 %13, 3
%15 = shl i8 %10, 2
%16 = add i8 %15, 12
%17 = and i8 %16, 12
%18 = or i8 %14, %17
%19 = or i8 %18, 48
%20 = zext i8 %19 to i32
br label %21
21: ; preds = %1, %5, %9
%22 = phi i32 [ %20, %9 ], [ -1, %5 ], [ -1, %1 ]
ret i32 %22
}