#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 */
char getbits(unsigned int, char, int);
void dec2bin(unsigned x, char s[]) {
  char i;
  int j;
  for (i = 32 - 1, j = 0; i >= 0; i--, j++) {
    s[j] = getbits(x, i, 1) + '0';
    if (!(i % 8)) {
    }
  }
}


x86 assembly (clang, -O0):
<dec2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1f,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jl     1190 <dec2bin+0x80>
mov    -0x4(%rbp),%edi
mov    $0x1,%edx
movsbl -0x11(%rbp),%esi
call   1030 <getbits@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x11(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1175 <dec2bin+0x65>
jmp    1175 <dec2bin+0x65>
jmp    117a <dec2bin+0x6a>
mov    -0x11(%rbp),%al
add    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <dec2bin+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2bin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x1f,%bl
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %bl,%ebx
mov    %r15d,%edi
mov    %ebx,%esi
mov    $0x1,%edx
call   1030 <getbits@plt>
add    $0x30,%al
mov    %al,(%r14,%rbp,1)
add    $0xff,%bl
add    $0x1,%rbp
cmp    $0x20,%rbp
jne    1130 <dec2bin+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dec2bin(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8 31, i8* %5
store i32 0, i32* %6
br label %7
7: ; preds = %28, %2
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i8, i8* %5
%14 = call signext i8 @getbits(i32 %12, i8 signext %13, i32 1)
%15 = sext i8 %14 to i32
%16 = add nsw i32 %15, 48
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = srem i32 %23, 8
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %11
br label %27
27: ; preds = %26, %11
br label %28
28: ; preds = %27
%29 = load i8, i8* %5
%30 = add i8 %29, -1
store i8 %30, i8* %5
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %7
33: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @dec2bin(i32 %0, i8* nocapture writeonly %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i64 [ 0, %2 ], [ %10, %3 ]
%5 = phi i8 [ 31, %2 ], [ %9, %3 ]
%6 = tail call signext i8 @getbits(i32 %0, i8 signext %5, i32 1)
%7 = add i8 %6, 48
%8 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %7, i8* %8
%9 = add nsw i8 %5, -1
%10 = add nuw nsw i64 %4, 1
%11 = icmp eq i64 %10, 32
br i1 %11, label %12, label %3
12: ; preds = %3
ret void
}