#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*/ add_opcode(int, int);
int begin_function(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
void moveq(int opcode) {
  char func_name[(100)];
  int func_id;
  if ((opcode & 0xF100) != 0x7000)
    return;
  sprintf(func_name, "moveq_%04X", opcode);
  func_id = begin_function(func_name);
  printf("\tREG_D(%d) = (uint32_t)(int8_t)0x%X;\n", (opcode >> 9) & 7,
         opcode & 0xFF);
  printf("\tSET_N_FLAG(%d);\n", (opcode & 0x80) ? 1 : 0);
  printf("\tSET_Z_FLAG(%d);\n", (opcode & 0xFF) ? 0 : 1);
  printf("\tSET_V_FLAG(0);\n");
  printf("\tSET_C_FLAG(0);\n");
  printf("\tFETCH_OPCODE;\n}\n\n");
  add_opcode(func_id, opcode);
}


x86 assembly (clang, -O0):
<moveq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf100,%eax
cmp    $0x7000,%eax
je     1166 <moveq+0x26>
jmp    1222 <moveq+0xe2>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8c(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <begin_function@plt>
mov    %eax,-0x74(%rbp)
mov    -0x4(%rbp),%esi
sar    $0x9,%esi
and    $0x7,%esi
mov    -0x4(%rbp),%edx
and    $0xff,%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
and    $0x80,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
mov    $0x1,%esi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x74(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <add_opcode@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<moveq>:
mov    %edi,%eax
and    $0xf100,%eax
cmp    $0x7000,%eax
jne    1212 <moveq+0xc2>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebx
lea    0xe8b(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <begin_function@plt>
mov    %eax,%r15d
mov    %ebx,%esi
shr    $0x9,%esi
and    $0x7,%esi
lea    0xe6f(%rip),%rdi
lea    0xe8e(%rip),%r14
xor    %ebp,%ebp
mov    %ebx,%edx
and    $0xff,%edx
sete   %bpl
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe72(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    %ebx,%esi
call   1050 <add_opcode@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"moveq_%04X\00"
@.str.1 = [38 x i8] c"\09REG_D(%d) = (uint32_t)(int8_t)0x%X;\0A\00"
@.str.2 = [18 x i8] c"\09SET_N_FLAG(%d);\0A\00"
@.str.3 = [18 x i8] c"\09SET_Z_FLAG(%d);\0A\00"
@.str.4 = [17 x i8] c"\09SET_V_FLAG(0);\0A\00"
@.str.5 = [17 x i8] c"\09SET_C_FLAG(0);\0A\00"
@.str.6 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define void @moveq(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = and i32 %5, 61696
%7 = icmp ne i32 %6, 28672
br i1 %7, label %8, label %9
8: ; preds = %1
br label %39
9: ; preds = %1
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* %2
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @begin_function(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = ashr i32 %15, 9
%17 = and i32 %16, 7
%18 = load i32, i32* %2
%19 = and i32 %18, 255
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
%21 = load i32, i32* %2
%22 = and i32 %21, 128
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
%28 = and i32 %27, 255
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 0, i32 1
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* %4
%37 = load i32, i32* %2
%38 = call i32 @add_opcode(i32 %36, i32 %37)
br label %39
39: ; preds = %9, %8
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"moveq_%04X\00"
@.str.1 = [38 x i8] c"\09REG_D(%d) = (uint32_t)(int8_t)0x%X;\0A\00"
@.str.2 = [18 x i8] c"\09SET_N_FLAG(%d);\0A\00"
@.str.3 = [18 x i8] c"\09SET_Z_FLAG(%d);\0A\00"
@str = [16 x i8] c"\09SET_V_FLAG(0);\00"
@str.7 = [16 x i8] c"\09SET_C_FLAG(0);\00"
@str.8 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
define void @moveq(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = and i32 %0, 61696
%5 = icmp eq i32 %4, 28672
br i1 %5, label %6, label %23
6: ; preds = %1
%7 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32 @begin_function(i8* %3)
%9 = lshr i32 %0, 9
%10 = and i32 %9, 7
%11 = and i32 %0, 255
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %11)
%13 = lshr i32 %0, 7
%14 = and i32 %13, 1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %11, 0
%17 = zext i1 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
%22 = call i32 @add_opcode(i32 %8, i32 %0)
br label %23
23: ; preds = %1, %6
ret void
}