#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 pow(int, int);
char *bin2str(char *bin, char num) {
  int i;
  char mask;
  for (i = 0; i < 8; i++) {
    mask = pow(2, i);
    bin[(7 - i)] = ((num & mask) ? '1' : '0');
  }
  bin[8] = '\0';
  return bin;
}


x86 assembly (clang, -O0):
<bin2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    117f <bin2str+0x6f>
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    %al,-0x11(%rbp)
movsbl -0x9(%rbp),%edx
movsbl -0x11(%rbp),%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1129 <bin2str+0x19>
mov    -0x8(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2str>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%r14b
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x7(%rbx)
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x6(%rbx)
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x5(%rbx)
mov    $0x2,%edi
mov    $0x3,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x4(%rbx)
mov    $0x2,%edi
mov    $0x4,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x3(%rbx)
mov    $0x2,%edi
mov    $0x5,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x2(%rbx)
mov    $0x2,%edi
mov    $0x6,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x1(%rbx)
mov    $0x2,%edi
mov    $0x7,%esi
call   1030 <pow@plt>
and    %bpl,%al
cmp    $0x1,%al
sbb    $0x0,%r14b
mov    %r14b,(%rbx)
movb   $0x0,0x8(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @bin2str(i8* returned writeonly %0, i8 signext %1) {
%3 = tail call signext i8 @pow(i32 2, i32 0)
%4 = and i8 %3, %1
%5 = icmp eq i8 %4, 0
%6 = select i1 %5, i8 48, i8 49
%7 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %6, i8* %7
%8 = tail call signext i8 @pow(i32 2, i32 1)
%9 = and i8 %8, %1
%10 = icmp eq i8 %9, 0
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %11, i8* %12
%13 = tail call signext i8 @pow(i32 2, i32 2)
%14 = and i8 %13, %1
%15 = icmp eq i8 %14, 0
%16 = select i1 %15, i8 48, i8 49
%17 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %16, i8* %17
%18 = tail call signext i8 @pow(i32 2, i32 3)
%19 = and i8 %18, %1
%20 = icmp eq i8 %19, 0
%21 = select i1 %20, i8 48, i8 49
%22 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %21, i8* %22
%23 = tail call signext i8 @pow(i32 2, i32 4)
%24 = and i8 %23, %1
%25 = icmp eq i8 %24, 0
%26 = select i1 %25, i8 48, i8 49
%27 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %26, i8* %27
%28 = tail call signext i8 @pow(i32 2, i32 5)
%29 = and i8 %28, %1
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i8 48, i8 49
%32 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %31, i8* %32
%33 = tail call signext i8 @pow(i32 2, i32 6)
%34 = and i8 %33, %1
%35 = icmp eq i8 %34, 0
%36 = select i1 %35, i8 48, i8 49
%37 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %36, i8* %37
%38 = tail call signext i8 @pow(i32 2, i32 7)
%39 = and i8 %38, %1
%40 = icmp eq i8 %39, 0
%41 = select i1 %40, i8 48, i8 49
store i8 %41, i8* %0
%42 = getelementptr inbounds i8, i8* %0, i64 8
store i8 0, i8* %42
ret i8* %0
}