#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 *, int);
unsigned int regnum(char *);
int /*<<< orphan*/ stderr;
unsigned code_i(int op, char *rx, char *ra, char *rb, int imm, int tag) {
  unsigned x = regnum(rx);
  unsigned a = regnum(ra);
  unsigned b = regnum(rb);
  unsigned c0, c1, c2, c3;
  if (!check_int_range(imm, 8)) {
    do {
      fprintf(stderr, "imm is too large %d\n", imm);
      exit(1);
    } while (0);
  }
  c0 = ((imm & 7) << 5) + tag;
  c1 = ((b & 7) << 5) + ((imm >> 3) & 31);
  c2 = ((x & 1) << 7) + (a << 2) + (b >> 3);
  c3 = (op << 4) + (x >> 1);
  return (c3 << 24) | (c2 << 16) | (c1 << 8) | c0;
}


x86 assembly (clang, -O0):
<code_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <regnum@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <regnum@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <regnum@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    $0x8,%esi
call   1030 <check_int_range@plt>
cmp    $0x0,%eax
jne    11c0 <code_i+0x80>
jmp    119e <code_i+0x5e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x24(%rbp),%eax
and    $0x7,%eax
shl    $0x5,%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
and    $0x7,%eax
shl    $0x5,%eax
mov    -0x24(%rbp),%ecx
sar    $0x3,%ecx
and    $0x1f,%ecx
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
mov    -0x30(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    -0x34(%rbp),%ecx
shr    $0x3,%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    -0x2c(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x18,%eax
mov    -0x40(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x3c(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x38(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<code_i>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r13d
mov    %r8d,%ebx
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <regnum@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1040 <regnum@plt>
mov    %rax,(%rsp)
mov    %r12,%rdi
call   1040 <regnum@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x8,%esi
call   1030 <check_int_range@plt>
test   %eax,%eax
je     11e7 <code_i+0xa7>
mov    %ebx,%eax
shl    $0x5,%eax
movzbl %al,%eax
add    %r13d,%eax
mov    %ebp,%ecx
shl    $0x5,%ecx
movzbl %cl,%ecx
shr    $0x3,%ebx
and    $0x1f,%ebx
or     %ecx,%ebx
mov    %r15d,%ecx
shl    $0x7,%ecx
movzbl %cl,%ecx
mov    (%rsp),%rdx
lea    (%rcx,%rdx,4),%ecx
shr    $0x3,%ebp
add    %ecx,%ebp
shl    $0x4,%r14d
shr    %r15d
add    %r14d,%r15d
shl    $0x18,%r15d
shl    $0x10,%ebp
or     %r15d,%ebp
shl    $0x8,%ebx
or     %ebp,%ebx
or     %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"imm is too large %d\0A\00"
define i32 @code_i(i32 %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%20 = load i8*, i8** %8
%21 = call i32 @regnum(i8* %20)
store i32 %21, i32* %13
%22 = load i8*, i8** %9
%23 = call i32 @regnum(i8* %22)
store i32 %23, i32* %14
%24 = load i8*, i8** %10
%25 = call i32 @regnum(i8* %24)
store i32 %25, i32* %15
%26 = load i32, i32* %11
%27 = call i32 @check_int_range(i32 %26, i32 8)
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %6
br label %30
30: ; preds = %29
%31 = load i32, i32* @stderr
%32 = load i32, i32* %11
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; No predecessors!
br label %36
36: ; preds = %35, %6
%37 = load i32, i32* %11
%38 = and i32 %37, 7
%39 = shl i32 %38, 5
%40 = load i32, i32* %12
%41 = add nsw i32 %39, %40
store i32 %41, i32* %16
%42 = load i32, i32* %15
%43 = and i32 %42, 7
%44 = shl i32 %43, 5
%45 = load i32, i32* %11
%46 = ashr i32 %45, 3
%47 = and i32 %46, 31
%48 = add i32 %44, %47
store i32 %48, i32* %17
%49 = load i32, i32* %13
%50 = and i32 %49, 1
%51 = shl i32 %50, 7
%52 = load i32, i32* %14
%53 = shl i32 %52, 2
%54 = add i32 %51, %53
%55 = load i32, i32* %15
%56 = lshr i32 %55, 3
%57 = add i32 %54, %56
store i32 %57, i32* %18
%58 = load i32, i32* %7
%59 = shl i32 %58, 4
%60 = load i32, i32* %13
%61 = lshr i32 %60, 1
%62 = add i32 %59, %61
store i32 %62, i32* %19
%63 = load i32, i32* %19
%64 = shl i32 %63, 24
%65 = load i32, i32* %18
%66 = shl i32 %65, 16
%67 = or i32 %64, %66
%68 = load i32, i32* %17
%69 = shl i32 %68, 8
%70 = or i32 %67, %69
%71 = load i32, i32* %16
%72 = or i32 %70, %71
ret i32 %72
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"imm is too large %d\0A\00"
define i32 @code_i(i32 %0, i8* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = tail call i32 @regnum(i8* %1)
%8 = tail call i32 @regnum(i8* %2)
%9 = tail call i32 @regnum(i8* %3)
%10 = tail call i32 @check_int_range(i32 %4, i32 8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = shl i32 %4, 5
%18 = and i32 %17, 224
%19 = add nsw i32 %18, %5
%20 = shl i32 %9, 5
%21 = and i32 %20, 224
%22 = lshr i32 %4, 3
%23 = and i32 %22, 31
%24 = or i32 %21, %23
%25 = shl i32 %7, 7
%26 = and i32 %25, 128
%27 = shl i32 %8, 2
%28 = add i32 %26, %27
%29 = lshr i32 %9, 3
%30 = add i32 %28, %29
%31 = shl i32 %0, 4
%32 = lshr i32 %7, 1
%33 = add i32 %32, %31
%34 = shl i32 %33, 24
%35 = shl i32 %30, 16
%36 = or i32 %34, %35
%37 = shl nuw nsw i32 %24, 8
%38 = or i32 %36, %37
%39 = or i32 %38, %19
ret i32 %39
}