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

/* Variables and functions */
int /*<<< orphan*/ binary_byte(int, char *);
char *to_binary(int32_t n, char *s, int is_big_end) {
  uint32_t un = (uint32_t)n;
  int i;
  if (is_big_end) {
    for (i = 3; i >= 0; i--) {
      binary_byte(un & ((1 << 8) - 1), s + i * 9);
      if (i != 0)
        s[i * 9 - 1] = ' ';
      un >>= 8;
    }
  } else {
    for (i = 0; i < 4; i++) {
      binary_byte(un & ((1 << 8) - 1), s + i * 9);
      if (i != 0)
        s[i * 9 - 1] = ' ';
      un >>= 8;
    }
  }
  s[4 * 9 - 1] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1196 <to_binary+0x86>
movl   $0x3,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1191 <to_binary+0x81>
mov    -0x18(%rbp),%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
imul   $0x9,-0x1c(%rbp),%eax
cltq
add    %rax,%rsi
call   1030 <binary_byte@plt>
cmpl   $0x0,-0x1c(%rbp)
je     117a <to_binary+0x6a>
mov    -0x10(%rbp),%rax
imul   $0x9,-0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <to_binary+0x29>
jmp    11fa <to_binary+0xea>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11f5 <to_binary+0xe5>
mov    -0x18(%rbp),%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
imul   $0x9,-0x1c(%rbp),%eax
cltq
add    %rax,%rsi
call   1030 <binary_byte@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11de <to_binary+0xce>
mov    -0x10(%rbp),%rax
imul   $0x9,-0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <to_binary+0x8d>
jmp    11fa <to_binary+0xea>
mov    -0x10(%rbp),%rax
movb   $0x0,0x23(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_binary>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movzbl %dil,%edi
test   %edx,%edx
je     1163 <to_binary+0x53>
lea    0x1b(%rbx),%rsi
call   1030 <binary_byte@plt>
movb   $0x20,0x1a(%rbx)
mov    %ebp,%eax
movzbl %ah,%edi
lea    0x12(%rbx),%rsi
call   1030 <binary_byte@plt>
movb   $0x20,0x11(%rbx)
mov    %ebp,%eax
shr    $0x10,%eax
movzbl %al,%edi
lea    0x9(%rbx),%rsi
call   1030 <binary_byte@plt>
movb   $0x20,0x8(%rbx)
shr    $0x18,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <binary_byte@plt>
jmp    11a4 <to_binary+0x94>
mov    %rbx,%rsi
call   1030 <binary_byte@plt>
mov    %ebp,%eax
movzbl %ah,%edi
lea    0x9(%rbx),%rsi
call   1030 <binary_byte@plt>
movb   $0x20,0x8(%rbx)
mov    %ebp,%eax
shr    $0x10,%eax
movzbl %al,%edi
lea    0x12(%rbx),%rsi
call   1030 <binary_byte@plt>
movb   $0x20,0x11(%rbx)
shr    $0x18,%ebp
lea    0x1b(%rbx),%rsi
mov    %ebp,%edi
call   1030 <binary_byte@plt>
movb   $0x20,0x1a(%rbx)
movb   $0x0,0x23(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @to_binary(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
store i32 %9, i32* %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %41
12: ; preds = %3
store i32 3, i32* %8
br label %13
13: ; preds = %37, %12
%14 = load i32, i32* %8
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %13
%17 = load i32, i32* %7
%18 = and i32 %17, 255
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = mul nsw i32 %20, 9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = call i32 @binary_byte(i32 %18, i8* %23)
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = mul nsw i32 %29, 9
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 32, i8* %33
br label %34
34: ; preds = %27, %16
%35 = load i32, i32* %7
%36 = ashr i32 %35, 8
store i32 %36, i32* %7
br label %37
37: ; preds = %34
%38 = load i32, i32* %8
%39 = add nsw i32 %38, -1
store i32 %39, i32* %8
br label %13
40: ; preds = %13
br label %70
41: ; preds = %3
store i32 0, i32* %8
br label %42
42: ; preds = %66, %41
%43 = load i32, i32* %8
%44 = icmp slt i32 %43, 4
br i1 %44, label %45, label %69
45: ; preds = %42
%46 = load i32, i32* %7
%47 = and i32 %46, 255
%48 = load i8*, i8** %5
%49 = load i32, i32* %8
%50 = mul nsw i32 %49, 9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = call i32 @binary_byte(i32 %47, i8* %52)
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %63
56: ; preds = %45
%57 = load i8*, i8** %5
%58 = load i32, i32* %8
%59 = mul nsw i32 %58, 9
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
store i8 32, i8* %62
br label %63
63: ; preds = %56, %45
%64 = load i32, i32* %7
%65 = ashr i32 %64, 8
store i32 %65, i32* %7
br label %66
66: ; preds = %63
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %42
69: ; preds = %42
br label %70
70: ; preds = %69, %40
%71 = load i8*, i8** %5
%72 = getelementptr inbounds i8, i8* %71, i64 35
store i8 0, i8* %72
%73 = load i8*, i8** %5
ret i8* %73
}

LLVM IR (-O2):
define i8* @to_binary(i32 %0, i8* returned %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = and i32 %0, 255
br i1 %4, label %22, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %1, i64 27
%8 = tail call i32 @binary_byte(i32 %5, i8* %7)
%9 = getelementptr inbounds i8, i8* %1, i64 26
store i8 32, i8* %9
%10 = lshr i32 %0, 8
%11 = and i32 %10, 255
%12 = getelementptr inbounds i8, i8* %1, i64 18
%13 = tail call i32 @binary_byte(i32 %11, i8* %12)
%14 = getelementptr inbounds i8, i8* %1, i64 17
store i8 32, i8* %14
%15 = lshr i32 %0, 16
%16 = and i32 %15, 255
%17 = getelementptr inbounds i8, i8* %1, i64 9
%18 = tail call i32 @binary_byte(i32 %16, i8* %17)
%19 = getelementptr inbounds i8, i8* %1, i64 8
store i8 32, i8* %19
%20 = lshr i32 %0, 24
%21 = tail call i32 @binary_byte(i32 %20, i8* %1)
br label %38
22: ; preds = %3
%23 = tail call i32 @binary_byte(i32 %5, i8* %1)
%24 = lshr i32 %0, 8
%25 = and i32 %24, 255
%26 = getelementptr inbounds i8, i8* %1, i64 9
%27 = tail call i32 @binary_byte(i32 %25, i8* %26)
%28 = getelementptr inbounds i8, i8* %1, i64 8
store i8 32, i8* %28
%29 = lshr i32 %0, 16
%30 = and i32 %29, 255
%31 = getelementptr inbounds i8, i8* %1, i64 18
%32 = tail call i32 @binary_byte(i32 %30, i8* %31)
%33 = getelementptr inbounds i8, i8* %1, i64 17
store i8 32, i8* %33
%34 = lshr i32 %0, 24
%35 = getelementptr inbounds i8, i8* %1, i64 27
%36 = tail call i32 @binary_byte(i32 %34, i8* %35)
%37 = getelementptr inbounds i8, i8* %1, i64 26
store i8 32, i8* %37
br label %38
38: ; preds = %6, %22
%39 = getelementptr inbounds i8, i8* %1, i64 35
store i8 0, i8* %39
ret i8* %1
}