#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char *);
int /*<<< orphan*/ stderr;
int stk_test(const char *instr, int file, int bit) {
  int flag = file & (1 << bit);
  fprintf(stderr, "test '%s': flag is %1d(%s)\n", instr, flag,
          flag ? "set" : "clear");
  return flag ? 1 : 0;
}


x86 assembly (clang, -O0):
<stk_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x14(%rbp),%esi
lea    0xed0(%rip),%r8
lea    0xec5(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%r8
lea    0xe9b(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stk_test>:
push   %rbx
mov    %edx,%ecx
mov    %rdi,%rdx
mov    $0x1,%eax
shl    %cl,%eax
mov    0x2ebc(%rip),%rcx
mov    (%rcx),%edi
xor    %ebx,%ebx
and    %esi,%eax
setne  %bl
lea    0xeec(%rip),%rcx
lea    0xee1(%rip),%r8
cmove  %rcx,%r8
lea    0xeba(%rip),%rsi
mov    %eax,%ecx
call   1030 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"test '%s': flag is %1d(%s)\0A\00"
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [6 x i8] c"clear\00"
define i32 @stk_test(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = shl i32 1, %9
%11 = and i32 %8, %10
store i32 %11, i32* %7
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = load i32, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14, i8* %18)
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 0
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"test '%s': flag is %1d(%s)\0A\00"
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [6 x i8] c"clear\00"
define i32 @stk_test(i8* %0, i32 %1, i32 %2) {
%4 = shl nuw i32 1, %2
%5 = and i32 %4, %1
%6 = load i32, i32* @stderr
%7 = icmp eq i32 %5, 0
%8 = select i1 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %5, i8* %8)
%10 = xor i1 %7, true
%11 = zext i1 %10 to i32
ret i32 %11
}