#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 getbits(unsigned int, char, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ putchar(char);
void dec2bin(unsigned x) {
  char i;
  for (i = 32 - 1; i >= 0; i--) {
    printf("%d", getbits(x, i, 1));
    if (!(i % 8)) {
      putchar(' ');
    }
  }
  printf(" = %d\n", x);
}


x86 assembly (clang, -O0):
<dec2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x1f,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jl     119c <dec2bin+0x6c>
mov    -0x4(%rbp),%edi
mov    $0x1,%edx
movsbl -0x5(%rbp),%esi
call   1050 <getbits@plt>
mov    %eax,%esi
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
movsbl -0x5(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118a <dec2bin+0x5a>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    118f <dec2bin+0x5f>
mov    -0x5(%rbp),%al
add    $0xff,%al
mov    %al,-0x5(%rbp)
jmp    113f <dec2bin+0xf>
mov    -0x4(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2bin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x1f,%bl
lea    0xebd(%rip),%r14
jmp    1155 <dec2bin+0x25>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xff,%bl
jae    1183 <dec2bin+0x53>
movsbl %bl,%ebp
mov    %r15d,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1050 <getbits@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   $0x7,%bpl
jne    1150 <dec2bin+0x20>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1150 <dec2bin+0x20>
lea    0xe79(%rip),%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c" = %d\0A\00"
define void @dec2bin(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
store i8 31, i8* %3
br label %4
4: ; preds = %20, %1
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = load i32, i32* %2
%10 = load i8, i8* %3
%11 = call i32 @getbits(i32 %9, i8 signext %10, i32 1)
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = srem i32 %14, 8
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %8
%18 = call i32 @putchar(i8 signext 32)
br label %19
19: ; preds = %17, %8
br label %20
20: ; preds = %19
%21 = load i8, i8* %3
%22 = add i8 %21, -1
store i8 %22, i8* %3
br label %4
23: ; preds = %4
%24 = load i32, i32* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c" = %d\0A\00"
define void @dec2bin(i32 %0) {
br label %2
2: ; preds = %1, %10
%3 = phi i8 [ 31, %1 ], [ %11, %10 ]
%4 = tail call i32 @getbits(i32 %0, i8 signext %3, i32 1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = and i8 %3, 7
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @putchar(i8 signext 32)
br label %10
10: ; preds = %2, %8
%11 = add nsw i8 %3, -1
%12 = icmp eq i8 %3, 0
br i1 %12, label %13, label %2
13: ; preds = %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %0)
ret void
}