#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
void write_by_half_octet(uint8_t *memory, size_t size) {
  for (size_t i = size; i--;) {
    uint8_t byte = memory[i];
    for (size_t j = 8; j-- > 4;) {
      printf("%d", (byte & (1 << j)) ? 1 : 0);
    }
    putchar(' ');
    for (size_t j = 4; j--;) {
      printf("%d", (byte & (1 << j)) ? 1 : 0);
    }
    putchar(" \n"[!i]);
  }
}


x86 assembly (clang, -O0):
<write_by_half_octet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     123e <write_by_half_octet+0x11e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
cmp    $0x4,%rax
jbe    11b6 <write_by_half_octet+0x96>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x34(%rbp),%ecx
and    %eax,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
jmp    1167 <write_by_half_octet+0x47>
mov    $0x20,%edi
call   1030 <putchar@plt>
movq   $0x4,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x0,%rax
je     1217 <write_by_half_octet+0xf7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x38(%rbp),%ecx
and    %eax,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
jmp    11c8 <write_by_half_octet+0xa8>
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rcx
lea    0xdd3(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    1138 <write_by_half_octet+0x18>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_by_half_octet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11fe <write_by_half_octet+0xde>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebf(%rip),%r15
lea    0xebb(%rip),%r12
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%r13
mov    -0x4(%r14,%rbx,4),%ebp
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %ebp,%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebp,%esi
shr    %esi
and    $0x1,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
and    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
cmp    $0x1,%rbx
sete   %al
movsbl (%rax,%r12,1),%edi
call   1030 <putchar@plt>
mov    %r13,%rbx
test   %r13,%r13
jne    1150 <write_by_half_octet+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c" \0A\00"
define void @write_by_half_octet(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
store i64 %9, i64* %5
br label %10
10: ; preds = %49, %2
%11 = load i64, i64* %5
%12 = add i64 %11, -1
store i64 %12, i64* %5
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %58
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i64, i64* %5
%17 = getelementptr inbounds i32, i32* %15, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %6
store i64 8, i64* %7
br label %19
19: ; preds = %23, %14
%20 = load i64, i64* %7
%21 = add i64 %20, -1
store i64 %21, i64* %7
%22 = icmp ugt i64 %20, 4
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %6
%25 = load i64, i64* %7
%26 = trunc i64 %25 to i32
%27 = shl i32 1, %26
%28 = and i32 %24, %27
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 1, i32 0
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %19
33: ; preds = %19
%34 = call i32 @putchar(i8 signext 32)
store i64 4, i64* %8
br label %35
35: ; preds = %39, %33
%36 = load i64, i64* %8
%37 = add i64 %36, -1
store i64 %37, i64* %8
%38 = icmp ne i64 %36, 0
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i32, i32* %6
%41 = load i64, i64* %8
%42 = trunc i64 %41 to i32
%43 = shl i32 1, %42
%44 = and i32 %40, %43
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 1, i32 0
%48 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %35
49: ; preds = %35
%50 = load i64, i64* %5
%51 = icmp ne i64 %50, 0
%52 = xor i1 %51, true
%53 = zext i1 %52 to i32
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [3 x i8], [3 x i8]* @.str.1, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @putchar(i8 signext %56)
br label %10
58: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c" \0A\00"
define void @write_by_half_octet(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %5
4: ; preds = %5, %2
ret void
5: ; preds = %2, %5
%6 = phi i64 [ %7, %5 ], [ %1, %2 ]
%7 = add i64 %6, -1
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = lshr i32 %9, 7
%11 = and i32 %10, 1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = lshr i32 %9, 6
%14 = and i32 %13, 1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = lshr i32 %9, 5
%17 = and i32 %16, 1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = lshr i32 %9, 4
%20 = and i32 %19, 1
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = tail call i32 @putchar(i8 signext 32)
%23 = lshr i32 %9, 3
%24 = and i32 %23, 1
%25 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = lshr i32 %9, 2
%27 = and i32 %26, 1
%28 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = lshr i32 %9, 1
%30 = and i32 %29, 1
%31 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = and i32 %9, 1
%33 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = icmp eq i64 %7, 0
%35 = zext i1 %34 to i64
%36 = getelementptr inbounds [3 x i8], [3 x i8]* @.str.1, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i32 @putchar(i8 signext %37)
br i1 %34, label %4, label %5
}