#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 /*<<< orphan*/ free(char *);
char *get_str();
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ valid_binary(char *);
char *get_binary(const char *number) {
  printf("Enter the %s number in binary format:\n", number);
  char *num;
  num = get_str();
  while (!valid_binary(num)) {
    printf("Input <%s> is not a valid binary literal\n", num);
    printf("Enter the %s number in binary format:\n", number);
    free(num);
    num = get_str();
  }
  return num;
}


x86 assembly (clang, -O0):
<get_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <get_str@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <valid_binary@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1185 <get_binary+0x45>
jmp    11be <get_binary+0x7e>
mov    -0x10(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1060 <get_str@plt>
mov    %rax,-0x10(%rbp)
jmp    1167 <get_binary+0x27>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_binary>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeae(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <valid_binary@plt>
test   %eax,%eax
jne    11b4 <get_binary+0x74>
lea    0xeb0(%rip),%r15
lea    0xe82(%rip),%r12
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1060 <get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <valid_binary@plt>
test   %eax,%eax
je     1180 <get_binary+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter the %s number in binary format:\0A\00"
@.str.1 = [42 x i8] c"Input <%s> is not a valid binary literal\0A\00"
define i8* @get_binary(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i8* (...) @get_str()
store i8* %6, i8** %3
br label %7
7: ; preds = %12, %1
%8 = load i8*, i8** %3
%9 = call i32 @valid_binary(i8* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %3
%18 = call i32 @free(i8* %17)
%19 = call i8* (...) @get_str()
store i8* %19, i8** %3
br label %7
20: ; preds = %7
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [39 x i8] c"Enter the %s number in binary format:\0A\00"
@.str.1 = [42 x i8] c"Input <%s> is not a valid binary literal\0A\00"
define i8* @get_binary(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i8* (...) @get_str()
%4 = tail call i32 @valid_binary(i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1, %6
%7 = phi i8* [ %11, %6 ], [ %3, %1 ]
%8 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i32 @free(i8* %7)
%11 = tail call i8* (...) @get_str()
%12 = tail call i32 @valid_binary(i8* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %1
%15 = phi i8* [ %3, %1 ], [ %11, %6 ]
ret i8* %15
}