#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 */
scalar_t__ getbits(unsigned int, int, int);
int /*<<< orphan*/ putchar(char);
void asbits(unsigned x, size_t s, int nl) {
  int i;
  for (i = s * 8 - 1; i >= 0; i--) {
    getbits(x, i, 1) ? putchar('1') : putchar('0');
    if (!(i % 4))
      putchar(' ');
  }
  if (nl)
    putchar('\n');
}


x86 assembly (clang, -O0):
<asbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
sub    $0x1,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11af <asbits+0x8f>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%edx
call   1040 <getbits@plt>
cmp    $0x0,%rax
je     1174 <asbits+0x54>
mov    $0x31,%edi
call   1030 <putchar@plt>
jmp    117e <asbits+0x5e>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119c <asbits+0x7c>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11a1 <asbits+0x81>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1141 <asbits+0x21>
cmpl   $0x0,-0x14(%rbp)
je     11c3 <asbits+0xa3>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asbits>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
shl    $0x3,%ebx
mov    %ebx,%eax
add    $0xffffffff,%eax
js     1177 <asbits+0x57>
mov    %edi,%ebp
jmp    1144 <asbits+0x24>
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    1177 <asbits+0x57>
add    $0xffffffff,%ebx
mov    %ebp,%edi
mov    %ebx,%esi
mov    $0x1,%edx
call   1040 <getbits@plt>
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
test   $0x3,%bl
jne    1140 <asbits+0x20>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1140 <asbits+0x20>
test   %r14d,%r14d
je     118a <asbits+0x6a>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @asbits(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = load i64, i64* %5
%9 = mul i64 %8, 8
%10 = sub i64 %9, 1
%11 = trunc i64 %10 to i32
store i32 %11, i32* %7
br label %12
12: ; preds = %32, %3
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %7
%18 = call i64 @getbits(i32 %16, i32 %17, i32 1)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @putchar(i8 signext 49)
br label %24
22: ; preds = %15
%23 = call i32 @putchar(i8 signext 48)
br label %24
24: ; preds = %22, %20
%25 = phi i32 [ %21, %20 ], [ %23, %22 ]
%26 = load i32, i32* %7
%27 = srem i32 %26, 4
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = call i32 @putchar(i8 signext 32)
br label %31
31: ; preds = %29, %24
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, -1
store i32 %34, i32* %7
br label %12
35: ; preds = %12
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @putchar(i8 signext 10)
br label %40
40: ; preds = %38, %35
ret void
}

LLVM IR (-O2):
define void @asbits(i32 %0, i64 %1, i32 %2) {
%4 = trunc i64 %1 to i32
%5 = shl i32 %4, 3
%6 = add i32 %5, -1
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %21
8: ; preds = %3, %18
%9 = phi i32 [ %19, %18 ], [ %6, %3 ]
%10 = tail call i64 @getbits(i32 %0, i32 %9, i32 1)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8 48, i8 49
%13 = tail call i32 @putchar(i8 signext %12)
%14 = and i32 %9, 3
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @putchar(i8 signext 32)
br label %18
18: ; preds = %8, %16
%19 = add nsw i32 %9, -1
%20 = icmp sgt i32 %9, 0
br i1 %20, label %8, label %21
21: ; preds = %18, %3
%22 = icmp eq i32 %2, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = tail call i32 @putchar(i8 signext 10)
br label %25
25: ; preds = %23, %21
ret void
}