#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 */
typedef int rt;
typedef int lopart;
typedef int base;

/* Variables and functions */
int /*<<< orphan*/ OUTINS(int);
unsigned int compute_real_offset(unsigned int imm, unsigned int base,
                                 unsigned int rt) {
  unsigned short hipart = imm >> 16;
  unsigned short lopart = imm & 0xFFFF;
  if (lopart >= 0x8000)
    hipart++;
  OUTINS((0x3c01 << 16) | hipart);
  if (base)
    OUTINS(((((0) & 63) << 26) | (((1) & 31) << 21) | (((base)&31) << 16) |
            (((1) & 31) << 11) | (((0) & 31) << 6) | ((33) & 63)));
  return ((((0) & 63) << 26) | (((1) & 31) << 21) | (((rt)&31) << 16) |
          ((lopart)&0xFFFF));
}


x86 assembly (clang, -O0):
<compute_real_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x10,%eax
mov    %ax,-0xe(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%eax
mov    %ax,-0x10(%rbp)
movzwl -0x10(%rbp),%eax
cmp    $0x8000,%eax
jl     1152 <compute_real_offset+0x42>
mov    -0xe(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xe(%rbp)
movzwl -0xe(%rbp),%edi
or     $0x3c010000,%edi
call   1030 <OUTINS@plt>
cmpl   $0x0,-0x8(%rbp)
je     118b <compute_real_offset+0x7b>
mov    -0x8(%rbp),%edi
and    $0x1f,%edi
shl    $0x10,%edi
or     $0x200000,%edi
or     $0x800,%edi
or     $0x0,%edi
or     $0x21,%edi
call   1030 <OUTINS@plt>
mov    -0xc(%rbp),%eax
and    $0x1f,%eax
shl    $0x10,%eax
or     $0x200000,%eax
movzwl -0x10(%rbp),%ecx
and    $0xffff,%ecx
or     %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_real_offset>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
movzwl %di,%r14d
shr    $0x10,%edi
cmp    $0x8000,%r14d
sbb    $0xffffffff,%edi
or     $0x3c010000,%edi
call   1030 <OUTINS@plt>
test   %ebp,%ebp
je     114b <compute_real_offset+0x3b>
and    $0x1f,%ebp
shl    $0x10,%ebp
or     $0x200821,%ebp
mov    %ebp,%edi
call   1030 <OUTINS@plt>
and    $0x1f,%ebx
shl    $0x10,%ebx
lea    (%r14,%rbx,1),%eax
add    $0x200000,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compute_real_offset(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = lshr i32 %9, 16
%11 = trunc i32 %10 to i16
store i16 %11, i16* %7
%12 = load i32, i32* %4
%13 = and i32 %12, 65535
%14 = trunc i32 %13 to i16
store i16 %14, i16* %8
%15 = load i16, i16* %8
%16 = zext i16 %15 to i32
%17 = icmp sge i32 %16, 32768
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i16, i16* %7
%20 = add i16 %19, 1
store i16 %20, i16* %7
br label %21
21: ; preds = %18, %3
%22 = load i16, i16* %7
%23 = zext i16 %22 to i32
%24 = or i32 1006698496, %23
%25 = call i32 @OUTINS(i32 %24)
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i32, i32* %5
%30 = and i32 %29, 31
%31 = shl i32 %30, 16
%32 = or i32 2097152, %31
%33 = or i32 %32, 2048
%34 = or i32 %33, 0
%35 = or i32 %34, 33
%36 = call i32 @OUTINS(i32 %35)
br label %37
37: ; preds = %28, %21
%38 = load i32, i32* %6
%39 = and i32 %38, 31
%40 = shl i32 %39, 16
%41 = or i32 2097152, %40
%42 = load i16, i16* %8
%43 = zext i16 %42 to i32
%44 = and i32 %43, 65535
%45 = or i32 %41, %44
ret i32 %45
}

LLVM IR (-O2):
define i32 @compute_real_offset(i32 %0, i32 %1, i32 %2) {
%4 = lshr i32 %0, 16
%5 = and i32 %0, 65535
%6 = icmp ugt i32 %5, 32767
%7 = zext i1 %6 to i32
%8 = add nuw nsw i32 %4, %7
%9 = or i32 %8, 1006698496
%10 = tail call i32 @OUTINS(i32 %9)
%11 = icmp eq i32 %1, 0
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = shl i32 %1, 16
%14 = and i32 %13, 2031616
%15 = or i32 %14, 2099233
%16 = tail call i32 @OUTINS(i32 %15)
br label %17
17: ; preds = %12, %3
%18 = shl i32 %2, 16
%19 = and i32 %18, 2031616
%20 = or i32 %5, %19
%21 = or i32 %20, 2097152
ret i32 %21
}