#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 ext(int opcode) {
  char func_name[(100)];
  int func_id;
  int op_size;
  op_size = ((opcode >> 6) & 1) + 1;
  if ((opcode & 0xFFB8) != 0x4880)
    return;
  sprintf(func_name, "ext_%04X", opcode);
  func_id = begin_function(func_name);
  printf("\tuint%d_t result = (int%d_t)REG_D(%d);\n", 8 << op_size,
         8 << (op_size - 1), opcode & 7);
  printf("\tSET_N_FLAG%d(result);\n", 8 << op_size);
  printf("\tSET_Z_FLAG%d(result);\n", 8 << op_size);
  printf("\tSET_V_FLAG(0);\n");
  printf("\tSET_C_FLAG(0);\n");
  printf("\tSET_DN_REG%d(%d, result);\n", 8 << op_size, opcode & 7);
  printf("\tFETCH_OPCODE;\n}\n\n");
  add_opcode(func_id, opcode);
}


x86 assembly (clang, -O0):
<ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
and    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffb8,%eax
cmp    $0x4880,%eax
je     1175 <ext+0x35>
jmp    1242 <ext+0x102>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1060 <begin_function@plt>
mov    %eax,-0x74(%rbp)
mov    -0x78(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0x78(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x8,%edx
shl    %cl,%edx
mov    -0x4(%rbp),%ecx
and    $0x7,%ecx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0x4(%rbp),%edx
and    $0x7,%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%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):
<ext>:
mov    %edi,%eax
and    $0xffb8,%eax
cmp    $0x4880,%eax
jne    122a <ext+0xda>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edi,%r15d
mov    %edi,%ebx
shr    $0x6,%ebx
and    $0x1,%ebx
lea    0xe82(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15d,%edx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1070 <begin_function@plt>
mov    %eax,%r14d
mov    $0x10,%ebp
mov    %ebx,%ecx
shl    %cl,%ebp
mov    $0x8,%edx
shl    %cl,%edx
mov    %r15d,%ebx
and    $0x7,%ebx
lea    0xe55(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
mov    %r15d,%esi
call   1050 <add_opcode@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"ext_%04X\00"
@.str.1 = [40 x i8] c"\09uint%d_t result = (int%d_t)REG_D(%d);\0A\00"
@.str.2 = [24 x i8] c"\09SET_N_FLAG%d(result);\0A\00"
@.str.3 = [24 x i8] c"\09SET_Z_FLAG%d(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_REG%d(%d, result);\0A\00"
@.str.7 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define void @ext(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = ashr i32 %6, 6
%8 = and i32 %7, 1
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load i32, i32* %2
%11 = and i32 %10, 65464
%12 = icmp ne i32 %11, 18560
br i1 %12, label %13, label %14
13: ; preds = %1
br label %45
14: ; preds = %1
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* %2
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i32 @begin_function(i8* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = shl i32 8, %20
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = shl i32 8, %23
%25 = load i32, i32* %2
%26 = and i32 %25, 7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24, i32 %26)
%28 = load i32, i32* %5
%29 = shl i32 8, %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %5
%32 = shl i32 8, %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%36 = load i32, i32* %5
%37 = shl i32 8, %36
%38 = load i32, i32* %2
%39 = and i32 %38, 7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %37, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32, i32* %4
%43 = load i32, i32* %2
%44 = call i32 @add_opcode(i32 %42, i32 %43)
br label %45
45: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"ext_%04X\00"
@.str.1 = [40 x i8] c"\09uint%d_t result = (int%d_t)REG_D(%d);\0A\00"
@.str.2 = [24 x i8] c"\09SET_N_FLAG%d(result);\0A\00"
@.str.3 = [24 x i8] c"\09SET_Z_FLAG%d(result);\0A\00"
@.str.6 = [28 x i8] c"\09SET_DN_REG%d(%d, result);\0A\00"
@str = [16 x i8] c"\09SET_V_FLAG(0);\00"
@str.8 = [16 x i8] c"\09SET_C_FLAG(0);\00"
@str.9 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
define void @ext(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = lshr i32 %0, 6
%5 = and i32 %4, 1
%6 = and i32 %0, 65464
%7 = icmp eq i32 %6, 18560
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = call i32 @begin_function(i8* %3)
%11 = shl nuw nsw i32 16, %5
%12 = shl nuw nsw i32 8, %5
%13 = and i32 %0, 7
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %11, i32 %13)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0))
%21 = call i32 @add_opcode(i32 %10, i32 %0)
br label %22
22: ; preds = %1, %8
ret void
}