#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 uint8_t;

/* Variables and functions */
void pic_update_mask(uint8_t *mask, uint8_t ins) {
  int c;
  *mask = 0;
  for (c = 0; c < 8; c++) {
    if (ins & (1 << c)) {
      *mask = 0xff << c;
      return;
    }
  }
}


x86 assembly (clang, -O0):
<pic_update_mask>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    116a <pic_update_mask+0x6a>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1157 <pic_update_mask+0x57>
mov    -0x10(%rbp),%ecx
mov    $0xff,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    116a <pic_update_mask+0x6a>
jmp    115c <pic_update_mask+0x5c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    111c <pic_update_mask+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<pic_update_mask>:
movl   $0x0,(%rdi)
xor    %ecx,%ecx
test   $0x1,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x1,%ecx
test   $0x2,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x2,%ecx
test   $0x4,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x3,%ecx
test   $0x8,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x4,%ecx
test   $0x10,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x5,%ecx
test   $0x20,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x6,%ecx
test   $0x40,%sil
jne    115c <pic_update_mask+0x5c>
mov    $0x7,%ecx
test   $0x80,%sil
jne    115c <pic_update_mask+0x5c>
ret
mov    $0xff,%eax
shl    %cl,%eax
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
define void @pic_update_mask(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = shl i32 1, %12
%14 = and i32 %11, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* %5
%18 = shl i32 255, %17
%19 = load i32*, i32** %3
store i32 %18, i32* %19
br label %24
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %16, %7
ret void
}

LLVM IR (-O2):
define void @pic_update_mask(i32* nocapture writeonly %0, i32 %1) {
store i32 0, i32* %0
%3 = and i32 %1, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %26, %23, %20, %17, %14, %11, %8, %2
%6 = phi i32 [ 0, %2 ], [ 1, %8 ], [ 2, %11 ], [ 3, %14 ], [ 4, %17 ], [ 5, %20 ], [ 6, %23 ], [ 7, %26 ]
%7 = shl nuw nsw i32 255, %6
store i32 %7, i32* %0
br label %29
8: ; preds = %2
%9 = and i32 %1, 2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8
%12 = and i32 %1, 4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %5
14: ; preds = %11
%15 = and i32 %1, 8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %5
17: ; preds = %14
%18 = and i32 %1, 16
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %17
%21 = and i32 %1, 32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %20
%24 = and i32 %1, 64
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %5
26: ; preds = %23
%27 = and i32 %1, 128
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %5
29: ; preds = %26, %5
ret void
}