#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 int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ debug_print(char *, int /*<<< orphan*/ *, char *, ...);
void print_in_bin(int32_t inst, FILE *out_file) {
  int32_t mask = 0;
  debug_print("@bw", out_file, "%08x", inst);
  debug_print("@bw", out_file, " [");
  for (int i = 0; i < 32; i++) {
    mask = 0x80000000 >> i;
    mask = mask & inst;
    mask = mask >> (31 - i);
    if (mask == -1)
      mask = 1;
    debug_print("@bw", out_file, "%d", mask);
  }
  debug_print("@bw", out_file, "]");
}


x86 assembly (clang, -O0):
<print_in_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%ecx
lea    0xecc(%rip),%rdi
lea    0xec9(%rip),%rdx
mov    $0x0,%al
call   1030 <debug_print@plt>
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
lea    0xeb5(%rip),%rdx
mov    $0x0,%al
call   1030 <debug_print@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jge    11cd <print_in_bin+0xbd>
mov    -0x18(%rbp),%ecx
mov    $0x80000000,%eax
shr    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x1f,%ecx
sub    -0x18(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a3 <print_in_bin+0x93>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xe4f(%rip),%rdi
lea    0xe54(%rip),%rdx
mov    $0x0,%al
call   1030 <debug_print@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <print_in_bin+0x52>
mov    -0x10(%rbp),%rsi
lea    0xe28(%rip),%rdi
lea    0xe30(%rip),%rdx
mov    $0x0,%al
call   1030 <debug_print@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_in_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r13d
lea    0xed8(%rip),%rbx
lea    0xed5(%rip),%rdx
mov    %rbx,%rdi
mov    %r13d,%ecx
xor    %eax,%eax
call   1030 <debug_print@plt>
lea    0xec6(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <debug_print@plt>
mov    $0x1f,%ebx
mov    $0x1,%r14d
lea    0xeaa(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x80000000,%eax
mov    %ebp,%ecx
shr    %cl,%eax
and    %r13d,%eax
mov    %ebx,%ecx
sar    %cl,%eax
cmp    $0xffffffff,%eax
cmove  %r14d,%eax
lea    0xe72(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <debug_print@plt>
add    $0x1,%ebp
add    $0xffffffff,%ebx
cmp    $0x20,%ebp
jne    1170 <print_in_bin+0x60>
lea    0xe51(%rip),%rdi
lea    0xe59(%rip),%rdx
mov    %r15,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <debug_print@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"@bw\00"
@.str.1 = [5 x i8] c"%08x\00"
@.str.2 = [3 x i8] c" [\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"]\00"
define void @print_in_bin(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %3
%9 = call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32*, i32** %4
%11 = call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 32
br i1 %14, label %15, label %35
15: ; preds = %12
%16 = load i32, i32* %6
%17 = lshr i32 -2147483648, %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = and i32 %18, %19
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = sub nsw i32 31, %22
%24 = ashr i32 %21, %23
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %15
store i32 1, i32* %5
br label %28
28: ; preds = %27, %15
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %12
35: ; preds = %12
%36 = load i32*, i32** %4
%37 = call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"@bw\00"
@.str.1 = [5 x i8] c"%08x\00"
@.str.2 = [3 x i8] c" [\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"]\00"
define void @print_in_bin(i32 %0, i32* %1) {
%3 = tail call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%4 = tail call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %7
5: ; preds = %7
%6 = tail call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %16, %7 ]
%9 = lshr i32 -2147483648, %8
%10 = and i32 %9, %0
%11 = sub nuw nsw i32 31, %8
%12 = ashr i32 %10, %11
%13 = icmp eq i32 %12, -1
%14 = select i1 %13, i32 1, i32 %12
%15 = tail call i32 (i8*, i32*, i8*, ...) @debug_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i32 %8, 1
%17 = icmp eq i32 %16, 32
br i1 %17, label %5, label %7
}