#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 swap(int opcode) {
  char func_name[(100)];
  int func_id;
  if ((opcode & 0xFFF8) != 0x4840)
    return;
  sprintf(func_name, "swap_%04X", opcode);
  func_id = begin_function(func_name);
  printf("\tuint32_t result = "
         "(((uint32_t)REG_D(%d))>>16)|(((uint32_t)REG_D(%d))<<16);\n",
         opcode & 7, opcode & 7);
  printf("\tSET_N_FLAG32(result);\n");
  printf("\tSET_Z_FLAG32(result);\n");
  printf("\tSET_V_FLAG(0);\n");
  printf("\tSET_C_FLAG(0);\n");
  printf("\tSET_DN_REG32(%d, result);\n", opcode & 7);
  printf("\tFETCH_OPCODE;\n}\n\n");
  add_opcode(func_id, opcode);
}


x86 assembly (clang, -O0):
<swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xfff8,%eax
cmp    $0x4840,%eax
je     1166 <swap+0x26>
jmp    1204 <swap+0xc4>
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
and    $0x7,%esi
mov    -0x4(%rbp),%edx
and    $0x7,%edx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
and    $0x7,%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%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):
<swap>:
mov    %edi,%eax
and    $0xfff8,%eax
cmp    $0x4840,%eax
jne    1200 <swap+0xb0>
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebp
lea    0xe8d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <begin_function@plt>
mov    %eax,%r14d
mov    %ebp,%ebx
and    $0x7,%ebx
lea    0xe73(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <add_opcode@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"swap_%04X\00"
@.str.1 = [77 x i8] c"\09uint32_t result = (((uint32_t)REG_D(%d))>>16)|(((uint32_t)REG_D(%d))<<16);\0A\00"
@.str.2 = [24 x i8] c"\09SET_N_FLAG32(result);\0A\00"
@.str.3 = [24 x i8] c"\09SET_Z_FLAG32(result);\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 = [28 x i8] c"\09SET_DN_REG32(%d, result);\0A\00"
@.str.7 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define void @swap(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, 65528
%7 = icmp ne i32 %6, 18496
br i1 %7, label %8, label %9
8: ; preds = %1
br label %31
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 ([10 x i8], [10 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 = and i32 %15, 7
%17 = load i32, i32* %2
%18 = and i32 %17, 7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = and i32 %24, 7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32, i32* %4
%29 = load i32, i32* %2
%30 = call i32 @add_opcode(i32 %28, i32 %29)
br label %31
31: ; preds = %9, %8
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"swap_%04X\00"
@.str.1 = [77 x i8] c"\09uint32_t result = (((uint32_t)REG_D(%d))>>16)|(((uint32_t)REG_D(%d))<<16);\0A\00"
@.str.6 = [28 x i8] c"\09SET_DN_REG32(%d, result);\0A\00"
@str = [23 x i8] c"\09SET_N_FLAG32(result);\00"
@str.8 = [23 x i8] c"\09SET_Z_FLAG32(result);\00"
@str.9 = [16 x i8] c"\09SET_V_FLAG(0);\00"
@str.10 = [16 x i8] c"\09SET_C_FLAG(0);\00"
@str.11 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
define void @swap(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, 65528
%5 = icmp eq i32 %4, 18496
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32 @begin_function(i8* %3)
%9 = and i32 %0, 7
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %9)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%17 = call i32 @add_opcode(i32 %8, i32 %0)
br label %18
18: ; preds = %1, %6
ret void
}