#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*/ check_int_range(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int regnum(char *);
int /*<<< orphan*/ stderr;
unsigned code_m(int op, char *rx, char *ra, int prd, int d, int disp_mode) {
  unsigned x = regnum(rx);
  unsigned a = regnum(ra);
  unsigned c0, c1, c2, c3;
  if (disp_mode == 0) {
    if (!(-0x8000 <= d && d <= 0xffff))
      do {
        fprintf(stderr, "imm too large %d\n", d);
        exit(1);
      } while (0);
  } else if (disp_mode == 1) {
    if (!(check_int_range(d, 16)))
      do {
        fprintf(stderr, "disp too large %d\n", d);
        exit(1);
      } while (0);
  } else {
    if ((d & 3) != 0)
      do {
        fprintf(stderr, "disp must be a mult of 4\n");
        exit(1);
      } while (0);
    if (!(check_int_range(d, 18)))
      do {
        fprintf(stderr, "disp too large %d\n", d);
        exit(1);
      } while (0);
    d >>= 2;
  }
  c0 = d & 255;
  c1 = (d >> 8) & 255;
  c2 = ((x & 1) << 7) + (a << 2) + prd;
  c3 = (op << 4) + (x >> 1);
  return (c3 << 24) | (c2 << 16) | (c1 << 8) | c0;
}


x86 assembly (clang, -O0):
<code_m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <regnum@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <regnum@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11c9 <code_m+0x89>
mov    $0xffff8000,%eax
cmp    -0x20(%rbp),%eax
jg     119b <code_m+0x5b>
cmpl   $0xffff,-0x20(%rbp)
jle    11c4 <code_m+0x84>
jmp    11a0 <code_m+0x60>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1299 <code_m+0x159>
cmpl   $0x1,-0x24(%rbp)
jne    1217 <code_m+0xd7>
mov    -0x20(%rbp),%edi
mov    $0x10,%esi
call   1030 <check_int_range@plt>
cmp    $0x0,%eax
jne    1212 <code_m+0xd2>
jmp    11ee <code_m+0xae>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1294 <code_m+0x154>
mov    -0x20(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     124c <code_m+0x10c>
jmp    122b <code_m+0xeb>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%edi
mov    $0x12,%esi
call   1030 <check_int_range@plt>
cmp    $0x0,%eax
jne    128b <code_m+0x14b>
jmp    1267 <code_m+0x127>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%eax
sar    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    1299 <code_m+0x159>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
mov    -0x2c(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    -0x28(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x18,%eax
mov    -0x38(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x34(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<code_m>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebx
mov    %r8d,%r13d
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <regnum@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <regnum@plt>
mov    %eax,%r12d
cmp    $0x1,%ebx
je     1198 <code_m+0x58>
test   %ebx,%ebx
jne    11ab <code_m+0x6b>
lea    0x8000(%r13),%eax
cmp    $0x18000,%eax
jb     11c6 <code_m+0x86>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
jmp    1214 <code_m+0xd4>
mov    %r13d,%edi
mov    $0x10,%esi
call   1030 <check_int_range@plt>
test   %eax,%eax
jne    11c6 <code_m+0x86>
jmp    1204 <code_m+0xc4>
test   $0x3,%r13b
jne    1228 <code_m+0xe8>
mov    %r13d,%edi
mov    $0x12,%esi
call   1030 <check_int_range@plt>
test   %eax,%eax
je     1204 <code_m+0xc4>
sar    $0x2,%r13d
movzbl %r13b,%ecx
and    $0xff00,%r13d
mov    %ebp,%eax
shl    $0x7,%eax
movzbl %al,%edx
lea    (%r15,%r12,4),%eax
add    %edx,%eax
shl    $0x4,%r14d
shr    %ebp
add    %r14d,%ebp
shl    $0x18,%ebp
shl    $0x10,%eax
or     %ebp,%eax
or     %r13d,%eax
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"imm too large %d\0A\00"
@.str.1 = [19 x i8] c"disp too large %d\0A\00"
@.str.2 = [26 x i8] c"disp must be a mult of 4\0A\00"
define i32 @code_m(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%19 = load i8*, i8** %8
%20 = call i32 @regnum(i8* %19)
store i32 %20, i32* %13
%21 = load i8*, i8** %9
%22 = call i32 @regnum(i8* %21)
store i32 %22, i32* %14
%23 = load i32, i32* %12
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %6
%26 = load i32, i32* %11
%27 = icmp sle i32 -32768, %26
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %11
%30 = icmp sle i32 %29, 65535
br i1 %30, label %38, label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31
%33 = load i32, i32* @stderr
%34 = load i32, i32* %11
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %28
br label %79
39: ; preds = %6
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i32, i32* %11
%44 = call i32 @check_int_range(i32 %43, i32 16)
%45 = icmp ne i32 %44, 0
br i1 %45, label %53, label %46
46: ; preds = %42
br label %47
47: ; preds = %46
%48 = load i32, i32* @stderr
%49 = load i32, i32* %11
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; No predecessors!
br label %53
53: ; preds = %52, %42
br label %78
54: ; preds = %39
%55 = load i32, i32* %11
%56 = and i32 %55, 3
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %54
br label %59
59: ; preds = %58
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; No predecessors!
br label %64
64: ; preds = %63, %54
%65 = load i32, i32* %11
%66 = call i32 @check_int_range(i32 %65, i32 18)
%67 = icmp ne i32 %66, 0
br i1 %67, label %75, label %68
68: ; preds = %64
br label %69
69: ; preds = %68
%70 = load i32, i32* @stderr
%71 = load i32, i32* %11
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %71)
%73 = call i32 @exit(i32 1)
unreachable
74: ; No predecessors!
br label %75
75: ; preds = %74, %64
%76 = load i32, i32* %11
%77 = ashr i32 %76, 2
store i32 %77, i32* %11
br label %78
78: ; preds = %75, %53
br label %79
79: ; preds = %78, %38
%80 = load i32, i32* %11
%81 = and i32 %80, 255
store i32 %81, i32* %15
%82 = load i32, i32* %11
%83 = ashr i32 %82, 8
%84 = and i32 %83, 255
store i32 %84, i32* %16
%85 = load i32, i32* %13
%86 = and i32 %85, 1
%87 = shl i32 %86, 7
%88 = load i32, i32* %14
%89 = shl i32 %88, 2
%90 = add i32 %87, %89
%91 = load i32, i32* %10
%92 = add i32 %90, %91
store i32 %92, i32* %17
%93 = load i32, i32* %7
%94 = shl i32 %93, 4
%95 = load i32, i32* %13
%96 = lshr i32 %95, 1
%97 = add i32 %94, %96
store i32 %97, i32* %18
%98 = load i32, i32* %18
%99 = shl i32 %98, 24
%100 = load i32, i32* %17
%101 = shl i32 %100, 16
%102 = or i32 %99, %101
%103 = load i32, i32* %16
%104 = shl i32 %103, 8
%105 = or i32 %102, %104
%106 = load i32, i32* %15
%107 = or i32 %105, %106
ret i32 %107
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"imm too large %d\0A\00"
@.str.1 = [19 x i8] c"disp too large %d\0A\00"
@.str.2 = [26 x i8] c"disp must be a mult of 4\0A\00"
define i32 @code_m(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @regnum(i8* %1)
%8 = tail call i32 @regnum(i8* %2)
switch i32 %5, label %23 [
i32 0, label %9
i32 1, label %16
]
9: ; preds = %6
%10 = add i32 %4, 32768
%11 = icmp ult i32 %10, 98304
br i1 %11, label %39, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = tail call i32 @check_int_range(i32 %4, i32 16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %6
%24 = and i32 %4, 3
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = tail call i32 @check_int_range(i32 %4, i32 18)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = ashr i32 %4, 2
br label %39
39: ; preds = %37, %16, %9
%40 = phi i32 [ %4, %9 ], [ %4, %16 ], [ %38, %37 ]
%41 = and i32 %40, 255
%42 = and i32 %40, 65280
%43 = shl i32 %7, 7
%44 = and i32 %43, 128
%45 = shl i32 %8, 2
%46 = add i32 %45, %3
%47 = add i32 %46, %44
%48 = shl i32 %0, 4
%49 = lshr i32 %7, 1
%50 = add i32 %49, %48
%51 = shl i32 %50, 24
%52 = shl i32 %47, 16
%53 = or i32 %52, %51
%54 = or i32 %53, %42
%55 = or i32 %54, %41
ret i32 %55
}