#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 */
struct compile_state {
  int dummy;
};

/* Variables and functions */
unsigned int arch_reg_regcm(struct compile_state *, int);
int do_select_reg(struct compile_state *state, char *used, int reg,
                  unsigned classes) {
  unsigned mask;
  if (used[reg]) {
    return 1;
  }
  mask = arch_reg_regcm(state, reg);
  return (classes & mask) ? reg : 1;
}


x86 assembly (clang, -O0):
<do_select_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1144 <do_select_reg+0x34>
movl   $0x1,-0x4(%rbp)
jmp    1180 <do_select_reg+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <arch_reg_regcm@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
and    -0x24(%rbp),%eax
cmp    $0x0,%eax
je     116d <do_select_reg+0x5d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    117a <do_select_reg+0x6a>
mov    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117a <do_select_reg+0x6a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_select_reg>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
movslq %edx,%rcx
mov    $0x1,%eax
cmpb   $0x0,(%rsi,%rcx,1)
jne    1136 <do_select_reg+0x26>
mov    %edx,%ebx
mov    %edx,%esi
call   1030 <arch_reg_regcm@plt>
test   %ebp,%eax
mov    $0x1,%eax
cmovne %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.compile_state = type { i32 }
define i32 @do_select_reg(%struct.compile_state* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.compile_state*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.compile_state* %0, %struct.compile_state** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 1, i32* %5
br label %31
18: ; preds = %4
%19 = load %struct.compile_state*, %struct.compile_state** %6
%20 = load i32, i32* %8
%21 = call i32 @arch_reg_regcm(%struct.compile_state* %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = load i32, i32* %8
br label %29
28: ; preds = %18
br label %29
29: ; preds = %28, %26
%30 = phi i32 [ %27, %26 ], [ 1, %28 ]
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %17
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.compile_state = type { i32 }
define i32 @do_select_reg(%struct.compile_state* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = tail call i32 @arch_reg_regcm(%struct.compile_state* %0, i32 %2)
%11 = and i32 %10, %3
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 1, i32 %2
br label %14
14: ; preds = %4, %9
%15 = phi i32 [ %13, %9 ], [ 1, %4 ]
ret i32 %15
}