#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 */
unsigned int find_maskwidth(unsigned char);
unsigned char GetSubID(unsigned char FullID, unsigned char MaxSubIDvalue,
                       unsigned char ShiftCount) {
  unsigned int MaskWidth, MaskBits, SubID;
  MaskWidth = find_maskwidth(MaxSubIDvalue);
  MaskBits = ((unsigned char)(0xff << ShiftCount)) ^
             ((unsigned char)(0xff << (ShiftCount + MaskWidth)));
  SubID = (FullID & MaskBits) >> ShiftCount;
  return SubID;
}


x86 assembly (clang, -O0):
<GetSubID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movzbl -0x2(%rbp),%edi
call   1030 <find_maskwidth@plt>
mov    %eax,-0x8(%rbp)
movzbl -0x3(%rbp),%ecx
mov    $0xff,%eax
shl    %cl,%eax
movzbl %al,%eax
movzbl -0x3(%rbp),%ecx
add    -0x8(%rbp),%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
movzbl -0x1(%rbp),%eax
and    -0xc(%rbp),%eax
movzbl -0x3(%rbp),%ecx
shr    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetSubID>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %edi,%ebp
mov    %esi,%edi
call   1030 <find_maskwidth@plt>
mov    $0xff,%edx
mov    $0xff,%esi
mov    %ebx,%ecx
shl    %cl,%esi
mov    %ebx,%ecx
add    %eax,%ecx
shl    %cl,%edx
xor    %esi,%edx
and    %ebp,%edx
mov    %ebx,%ecx
shr    %cl,%edx
mov    %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @GetSubID(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%10 = load i8, i8* %5
%11 = call i32 @find_maskwidth(i8 zeroext %10)
store i32 %11, i32* %7
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = shl i32 255, %13
%15 = trunc i32 %14 to i8
%16 = zext i8 %15 to i32
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = load i32, i32* %7
%20 = add i32 %18, %19
%21 = shl i32 255, %20
%22 = trunc i32 %21 to i8
%23 = zext i8 %22 to i32
%24 = xor i32 %16, %23
store i32 %24, i32* %8
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = load i32, i32* %8
%28 = and i32 %26, %27
%29 = load i8, i8* %6
%30 = zext i8 %29 to i32
%31 = lshr i32 %28, %30
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = trunc i32 %32 to i8
ret i8 %33
}

LLVM IR (-O2):
define zeroext i8 @GetSubID(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = tail call i32 @find_maskwidth(i8 zeroext %1)
%5 = zext i8 %2 to i32
%6 = shl i32 255, %5
%7 = add i32 %4, %5
%8 = shl i32 255, %7
%9 = xor i32 %8, %6
%10 = zext i8 %0 to i32
%11 = and i32 %9, %10
%12 = lshr i32 %11, %5
%13 = trunc i32 %12 to i8
ret i8 %13
}