void foo(unsigned long base, unsigned char val) {
  val ^= (1 << 2);
  bar(val & (1 << 5) ? "1" : "2");
  bar(val & (1 << 4) ? "1" : "2");
  bar(val & (1 << 3) ? "1" : "2");
  bar(val & (1 << 2) ? "1" : "2");
  bar(val & (1 << 1) ? "1" : "2");
  bar(val & (1 << 0) ? "1" : "2");
  asm volatile("" : : "a"(val), "d"(base));
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
xor    $0x4,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%ecx
and    $0x20,%ecx
lea    0xec8(%rip),%rdi
lea    0xebf(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
movzbl -0x9(%rbp),%ecx
and    $0x10,%ecx
lea    0xea5(%rip),%rdi
lea    0xe9c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
movzbl -0x9(%rbp),%ecx
and    $0x8,%ecx
lea    0xe82(%rip),%rdi
lea    0xe79(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
movzbl -0x9(%rbp),%ecx
and    $0x4,%ecx
lea    0xe5f(%rip),%rdi
lea    0xe56(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
movzbl -0x9(%rbp),%ecx
and    $0x2,%ecx
lea    0xe3c(%rip),%rdi
lea    0xe33(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
movzbl -0x9(%rbp),%ecx
and    $0x1,%ecx
lea    0xe19(%rip),%rdi
lea    0xe10(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <bar@plt>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rdx
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
xor    $0x4,%bpl
test   $0x20,%bpl
lea    0xed7(%rip),%r15
lea    0xece(%rip),%rbx
mov    %rbx,%rdi
cmove  %r15,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
test   $0x10,%bpl
mov    %rbx,%rdi
cmove  %r15,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
test   $0x8,%bpl
mov    %rbx,%rdi
cmove  %r15,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
test   $0x4,%bpl
mov    %rbx,%rdi
cmove  %r15,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
test   $0x2,%bpl
mov    %rbx,%rdi
cmove  %r15,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
test   $0x1,%bpl
cmove  %r15,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <bar@plt>
mov    %ebp,%eax
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"2\00"
define void @foo(i64 %0, i8 zeroext %1) {
%3 = alloca i64
%4 = alloca i8
store i64 %0, i64* %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = xor i32 %6, 4
%8 = trunc i32 %7 to i8
store i8 %8, i8* %4
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = and i32 %10, 32
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %14)
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = and i32 %17, 16
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%22 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %21)
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = and i32 %24, 8
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%29 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %28)
%30 = load i8, i8* %4
%31 = zext i8 %30 to i32
%32 = and i32 %31, 4
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%36 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %35)
%37 = load i8, i8* %4
%38 = zext i8 %37 to i32
%39 = and i32 %38, 2
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%43 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %42)
%44 = load i8, i8* %4
%45 = zext i8 %44 to i32
%46 = and i32 %45, 1
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%50 = call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %49)
%51 = load i8, i8* %4
%52 = load i64, i64* %3
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"2\00"
define void @foo(i64 %0, i8 zeroext %1) {
%3 = xor i8 %1, 4
%4 = zext i8 %3 to i32
%5 = and i32 %4, 32
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %7)
%9 = and i32 %4, 16
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %11)
%13 = and i32 %4, 8
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%16 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %15)
%17 = and i32 %4, 4
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%20 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %19)
%21 = and i32 %4, 2
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%24 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %23)
%25 = and i32 %4, 1
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%28 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bar to i32 (i8*, ...)*)(i8* %27)
tail call void asm sideeffect "", "{ax},{dx},~{dirflag},~{fpsr},~{flags}"(i8 %3, i64 %0)
ret void
}