#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*/ fprintf(int /*<<< orphan*/, char *, short);
int /*<<< orphan*/ stderr;
volatile char *build_mov_register_to_register(short mov_size, int src_reg,
                                              int dest_reg,
                                              volatile char *tgt_addr) {
  if (mov_size == 2) {
    (*tgt_addr++) = 0x66;
  }
  switch (mov_size) {
  case 1:
    (*(short *)tgt_addr) = ((0xc0) + (dest_reg << 0x3) + src_reg) << 8 | 0x8a;
    tgt_addr += 0x2;
    break;
  case 2:
    (*(short *)tgt_addr) = ((0xc0) + (dest_reg << 0x3) + src_reg) << 8 | 0x8b;
    tgt_addr += 0x2;
    break;
  case 4:
    (*(short *)tgt_addr) = ((0xc0) + (dest_reg << 0x3) + src_reg) << 8 | 0x8b;
    tgt_addr += 0x2;
    break;
  default:
    fprintf(stderr,
            "ERROR: Incorrect size (%d) passed to register to register move\n",
            mov_size);
    return (NULL);
  }
  return (tgt_addr);
}


x86 assembly (clang, -O0):
<build_mov_register_to_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movswl -0xa(%rbp),%eax
cmp    $0x2,%eax
jne    1148 <build_mov_register_to_register+0x38>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x66,(%rax)
movswl -0xa(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     117f <build_mov_register_to_register+0x6f>
jmp    115d <build_mov_register_to_register+0x4d>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     11b0 <build_mov_register_to_register+0xa0>
jmp    116e <build_mov_register_to_register+0x5e>
mov    -0x24(%rbp),%eax
sub    $0x4,%eax
je     11e1 <build_mov_register_to_register+0xd1>
jmp    1212 <build_mov_register_to_register+0x102>
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
add    $0xc0,%eax
add    -0x10(%rbp),%eax
shl    $0x8,%eax
or     $0x8a,%eax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1238 <build_mov_register_to_register+0x128>
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
add    $0xc0,%eax
add    -0x10(%rbp),%eax
shl    $0x8,%eax
or     $0x8b,%eax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1238 <build_mov_register_to_register+0x128>
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
add    $0xc0,%eax
add    -0x10(%rbp),%eax
shl    $0x8,%eax
or     $0x8b,%eax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1238 <build_mov_register_to_register+0x128>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
movswl -0xa(%rbp),%edx
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1240 <build_mov_register_to_register+0x130>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_mov_register_to_register>:
push   %rax
mov    %rcx,%rax
cmp    $0x2,%di
jne    1123 <build_mov_register_to_register+0x13>
movb   $0x66,(%rax)
add    $0x1,%rax
jmp    1135 <build_mov_register_to_register+0x25>
movswl %di,%ecx
cmp    $0x1,%ecx
je     1153 <build_mov_register_to_register+0x43>
cmp    $0x4,%ecx
je     1135 <build_mov_register_to_register+0x25>
cmp    $0x2,%ecx
jne    1159 <build_mov_register_to_register+0x49>
mov    $0x8b,%cx
lea    (%rsi,%rdx,8),%edx
shl    $0x8,%edx
movzwl %cx,%ecx
add    %edx,%ecx
add    $0xffffc000,%ecx
mov    %cx,(%rax)
add    $0x2,%rax
pop    %rcx
ret
mov    $0x8a,%cx
jmp    1139 <build_mov_register_to_register+0x29>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %ecx,%edx
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [64 x i8] c"ERROR: Incorrect size (%d) passed to register to register move\0A\00"
define i8* @build_mov_register_to_register(i16 signext %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i16 %0, i16* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%10 = load i16, i16* %6
%11 = sext i16 %10 to i32
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i8*, i8** %9
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %9
store volatile i8 102, i8* %14
br label %16
16: ; preds = %13, %4
%17 = load i16, i16* %6
%18 = sext i16 %17 to i32
switch i32 %18, label %58 [
i32 1, label %19
i32 2, label %32
i32 4, label %45
]
19: ; preds = %16
%20 = load i32, i32* %8
%21 = shl i32 %20, 3
%22 = add nsw i32 192, %21
%23 = load i32, i32* %7
%24 = add nsw i32 %22, %23
%25 = shl i32 %24, 8
%26 = or i32 %25, 138
%27 = trunc i32 %26 to i16
%28 = load i8*, i8** %9
%29 = bitcast i8* %28 to i16*
store i16 %27, i16* %29
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 2
store i8* %31, i8** %9
br label %62
32: ; preds = %16
%33 = load i32, i32* %8
%34 = shl i32 %33, 3
%35 = add nsw i32 192, %34
%36 = load i32, i32* %7
%37 = add nsw i32 %35, %36
%38 = shl i32 %37, 8
%39 = or i32 %38, 139
%40 = trunc i32 %39 to i16
%41 = load i8*, i8** %9
%42 = bitcast i8* %41 to i16*
store i16 %40, i16* %42
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %9
br label %62
45: ; preds = %16
%46 = load i32, i32* %8
%47 = shl i32 %46, 3
%48 = add nsw i32 192, %47
%49 = load i32, i32* %7
%50 = add nsw i32 %48, %49
%51 = shl i32 %50, 8
%52 = or i32 %51, 139
%53 = trunc i32 %52 to i16
%54 = load i8*, i8** %9
%55 = bitcast i8* %54 to i16*
store i16 %53, i16* %55
%56 = load i8*, i8** %9
%57 = getelementptr inbounds i8, i8* %56, i64 2
store i8* %57, i8** %9
br label %62
58: ; preds = %16
%59 = load i32, i32* @stderr
%60 = load i16, i16* %6
%61 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i16 signext %60)
store i8* null, i8** %5
br label %64
62: ; preds = %45, %32, %19
%63 = load i8*, i8** %9
store i8* %63, i8** %5
br label %64
64: ; preds = %62, %58
%65 = load i8*, i8** %5
ret i8* %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [64 x i8] c"ERROR: Incorrect size (%d) passed to register to register move\0A\00"
define i8* @build_mov_register_to_register(i16 signext %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp eq i16 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %3, i64 1
store volatile i8 102, i8* %3
br label %10
8: ; preds = %4
%9 = sext i16 %0 to i32
switch i32 %9, label %13 [
i32 1, label %16
i32 2, label %10
i32 4, label %12
]
10: ; preds = %6, %8
%11 = phi i8* [ %7, %6 ], [ %3, %8 ]
br label %16
12: ; preds = %8
br label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i16 signext %0)
br label %27
16: ; preds = %8, %12, %10
%17 = phi i16 [ 139, %12 ], [ 139, %10 ], [ 138, %8 ]
%18 = phi i8* [ %3, %12 ], [ %11, %10 ], [ %3, %8 ]
%19 = shl i32 %2, 3
%20 = add i32 %1, 192
%21 = add i32 %20, %19
%22 = trunc i32 %21 to i16
%23 = shl i16 %22, 8
%24 = or i16 %23, %17
%25 = bitcast i8* %18 to i16*
store i16 %24, i16* %25
%26 = getelementptr inbounds i8, i8* %18, i64 2
br label %27
27: ; preds = %16, %13
%28 = phi i8* [ null, %13 ], [ %26, %16 ]
ret i8* %28
}