#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 */
scalar_t__ malloc(int);
unsigned char *translate_char_to_binary_string(char input) {
  int i;
  unsigned char *binary_string = (unsigned char *)malloc(9 * sizeof(char));
  for (i = 0; i < 8; i++) {
    char shift_byte = 0x01 << (7 - i);
    if (shift_byte & input) {
      binary_string[i] = '1';
    } else {
      binary_string[i] = '0';
    }
  }
  binary_string[8] = '\0';
  return binary_string;
}


x86 assembly (clang, -O0):
<translate_char_to_binary_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1192 <translate_char_to_binary_string+0x82>
mov    $0x7,%ecx
sub    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
movsbl -0x1(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1173 <translate_char_to_binary_string+0x63>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    117f <translate_char_to_binary_string+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    1184 <translate_char_to_binary_string+0x74>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1133 <translate_char_to_binary_string+0x23>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_char_to_binary_string>:
push   %rbx
mov    %edi,%ebx
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %ebx,%ecx
shr    $0x7,%cl
or     $0x30,%cl
mov    %cl,(%rax)
mov    %ebx,%ecx
and    $0x40,%ecx
cmp    $0x1,%ecx
mov    $0x31,%cl
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x1(%rax)
mov    %ebx,%edx
and    $0x20,%edx
cmp    $0x1,%edx
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x2(%rax)
mov    %ebx,%edx
and    $0x10,%edx
cmp    $0x1,%edx
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x3(%rax)
mov    %ebx,%edx
and    $0x8,%edx
cmp    $0x1,%edx
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x4(%rax)
mov    %ebx,%edx
and    $0x4,%edx
cmp    $0x1,%edx
mov    $0x31,%dl
sbb    $0x0,%dl
mov    %dl,0x5(%rax)
mov    %ebx,%edx
and    $0x2,%edx
cmp    $0x1,%edx
sbb    $0x0,%cl
mov    %cl,0x6(%rax)
and    $0x1,%bl
or     $0x30,%bl
mov    %bl,0x7(%rax)
movb   $0x0,0x8(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @translate_char_to_binary_string(i8 signext %0) {
%2 = tail call i64 @malloc(i32 9)
%3 = inttoptr i64 %2 to i8*
%4 = sext i8 %0 to i32
%5 = icmp sgt i8 %0, -1
%6 = select i1 %5, i8 48, i8 49
store i8 %6, i8* %3
%7 = and i32 %4, 64
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8 48, i8 49
%10 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %9, i8* %10
%11 = and i32 %4, 32
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8 48, i8 49
%14 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %13, i8* %14
%15 = and i32 %4, 16
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8 48, i8 49
%18 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %17, i8* %18
%19 = and i32 %4, 8
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8 48, i8 49
%22 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %21, i8* %22
%23 = and i32 %4, 4
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8 48, i8 49
%26 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %25, i8* %26
%27 = and i32 %4, 2
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i8 48, i8 49
%30 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %29, i8* %30
%31 = and i32 %4, 1
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i8 48, i8 49
%34 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %3, i64 8
store i8 0, i8* %35
ret i8* %3
}