#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 */
void s_itob(unsigned int n, char *s, bool space) {
  int i;
  for (i = 31; i >= 0; i--) {
    if (n & (1 << i)) {
      *s++ = '1';
    } else {
      *s++ = '0';
    }
    if (space && (i & 0x7) == 0) {
      *s++ = ' ';
    }
  }
  *s = '\0';
}


x86 assembly (clang, -O0):
<s_itob>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1f,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11a0 <s_itob+0xa0>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1150 <s_itob+0x50>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x31,(%rax)
jmp    1162 <s_itob+0x62>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x30,(%rax)
cmpl   $0x0,-0x14(%rbp)
je     118d <s_itob+0x8d>
mov    -0x18(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    118d <s_itob+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x20,(%rax)
jmp    1192 <s_itob+0x92>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1115 <s_itob+0x15>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_itob>:
mov    $0x1e,%r8d
jmp    1119 <s_itob+0x19>
nopl   0x0(%rax,%rax,1)
add    $0xfffffffe,%r8d
test   %r9d,%r9d
je     116f <s_itob+0x6f>
lea    0x1(%r8),%r9d
bt     %r9d,%edi
mov    $0x31,%cl
adc    $0xff,%cl
lea    0x1(%rsi),%rax
mov    %cl,(%rsi)
test   %edx,%edx
je     1143 <s_itob+0x43>
mov    %r9d,%ecx
and    $0x7,%ecx
jne    1143 <s_itob+0x43>
movb   $0x20,0x1(%rsi)
add    $0x2,%rsi
mov    %rsi,%rax
add    $0xffffffff,%r9d
bt     %r9d,%edi
mov    $0x31,%cl
adc    $0xff,%cl
lea    0x1(%rax),%rsi
mov    %cl,(%rax)
test   %edx,%edx
je     1110 <s_itob+0x10>
mov    %r8d,%ecx
and    $0x7,%ecx
jne    1110 <s_itob+0x10>
movb   $0x20,0x1(%rax)
add    $0x2,%rax
mov    %rax,%rsi
jmp    1110 <s_itob+0x10>
movb   $0x0,(%rsi)
ret

LLVM IR (-O0):
define void @s_itob(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 31, i32* %7
br label %8
8: ; preds = %34, %3
%9 = load i32, i32* %7
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %7
%14 = shl i32 1, %13
%15 = and i32 %12, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
store i8 49, i8* %18
br label %23
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
store i8 48, i8* %21
br label %23
23: ; preds = %20, %17
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %7
%28 = and i32 %27, 7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 32, i8* %31
br label %33
33: ; preds = %30, %26, %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
br label %8
37: ; preds = %8
%38 = load i8*, i8** %5
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @s_itob(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp ne i32 %2, 0
br label %5
5: ; preds = %31, %3
%6 = phi i32 [ 31, %3 ], [ %33, %31 ]
%7 = phi i8* [ %1, %3 ], [ %32, %31 ]
%8 = shl nuw i32 1, %6
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = and i32 %6, 7
%14 = icmp eq i32 %13, 0
%15 = select i1 %4, i1 %14, i1 false
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = getelementptr inbounds i8, i8* %7, i64 2
store i8 32, i8* %12
br label %18
18: ; preds = %5, %16
%19 = phi i8* [ %17, %16 ], [ %12, %5 ]
%20 = add nsw i32 %6, -1
%21 = shl nuw i32 1, %20
%22 = and i32 %21, %0
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8 48, i8 49
%25 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %24, i8* %19
%26 = and i32 %20, 7
%27 = icmp eq i32 %26, 0
%28 = select i1 %4, i1 %27, i1 false
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = getelementptr inbounds i8, i8* %19, i64 2
store i8 32, i8* %25
br label %31
31: ; preds = %29, %18
%32 = phi i8* [ %30, %29 ], [ %25, %18 ]
%33 = add nsw i32 %6, -2
%34 = icmp eq i32 %20, 0
br i1 %34, label %35, label %5
35: ; preds = %31
store i8 0, i8* %32
ret void
}