#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 pow(int, int);
int /*<<< orphan*/ printf(char *);
int bin2txt(int byte) {
  int idx;
  int result;
  for (idx = 7; idx >= 0; idx--) {
    result = pow(2, idx);
    if (byte >= result) {
      byte -= result;
      printf("1");
    } else {
      printf("0");
    }
  }
  printf(" ");
  return 0;
}


x86 assembly (clang, -O0):
<bin2txt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1193 <bin2txt+0x73>
mov    -0x8(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1174 <bin2txt+0x54>
mov    -0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
jmp    1180 <bin2txt+0x60>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <bin2txt+0x65>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <bin2txt+0x12>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2txt>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x2,%edi
mov    $0x7,%esi
call   1040 <pow@plt>
xor    %ebp,%ebp
xor    %edi,%edi
cmp    %ebx,%eax
setg   %dil
cmovg  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x6,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x5,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x4,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x3,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x2,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    $0x1,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
cmovl  %ebp,%eax
xor    $0x31,%edi
sub    %eax,%ebx
call   1030 <putchar@plt>
mov    $0x2,%edi
xor    %esi,%esi
call   1040 <pow@plt>
xor    %edi,%edi
cmp    %eax,%ebx
setl   %dil
xor    $0x31,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c" \00"
define i32 @bin2txt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 7, i32* %3
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i32, i32* %3
%10 = call i32 @pow(i32 2, i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = icmp sge i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, %15
store i32 %17, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
19: ; preds = %8
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
br label %22
22: ; preds = %21
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %5
25: ; preds = %5
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
define i32 @bin2txt(i32 %0) {
%2 = tail call i32 @pow(i32 2, i32 7)
%3 = icmp sgt i32 %2, %0
%4 = select i1 %3, i32 48, i32 49
%5 = select i1 %3, i32 0, i32 %2
%6 = sub nsw i32 %0, %5
%7 = tail call i32 @putchar(i32 %4)
%8 = tail call i32 @pow(i32 2, i32 6)
%9 = icmp slt i32 %6, %8
%10 = select i1 %9, i32 48, i32 49
%11 = select i1 %9, i32 0, i32 %8
%12 = sub nsw i32 %6, %11
%13 = tail call i32 @putchar(i32 %10)
%14 = tail call i32 @pow(i32 2, i32 5)
%15 = icmp slt i32 %12, %14
%16 = select i1 %15, i32 48, i32 49
%17 = select i1 %15, i32 0, i32 %14
%18 = sub nsw i32 %12, %17
%19 = tail call i32 @putchar(i32 %16)
%20 = tail call i32 @pow(i32 2, i32 4)
%21 = icmp slt i32 %18, %20
%22 = select i1 %21, i32 48, i32 49
%23 = select i1 %21, i32 0, i32 %20
%24 = sub nsw i32 %18, %23
%25 = tail call i32 @putchar(i32 %22)
%26 = tail call i32 @pow(i32 2, i32 3)
%27 = icmp slt i32 %24, %26
%28 = select i1 %27, i32 48, i32 49
%29 = select i1 %27, i32 0, i32 %26
%30 = sub nsw i32 %24, %29
%31 = tail call i32 @putchar(i32 %28)
%32 = tail call i32 @pow(i32 2, i32 2)
%33 = icmp slt i32 %30, %32
%34 = select i1 %33, i32 48, i32 49
%35 = select i1 %33, i32 0, i32 %32
%36 = sub nsw i32 %30, %35
%37 = tail call i32 @putchar(i32 %34)
%38 = tail call i32 @pow(i32 2, i32 1)
%39 = icmp slt i32 %36, %38
%40 = select i1 %39, i32 48, i32 49
%41 = select i1 %39, i32 0, i32 %38
%42 = sub nsw i32 %36, %41
%43 = tail call i32 @putchar(i32 %40)
%44 = tail call i32 @pow(i32 2, i32 0)
%45 = icmp slt i32 %42, %44
%46 = select i1 %45, i32 48, i32 49
%47 = tail call i32 @putchar(i32 %46)
%48 = tail call i32 @putchar(i32 32)
ret i32 0
}