#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 *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strip_nonbinary(char *string) {
  char *tmp_string = malloc(sizeof(char *) * 8);
  strcpy(tmp_string, string);
  for (int i = 0; i < strlen(tmp_string); i++) {
    if (tmp_string[i] != '0' && tmp_string[i] != '1') {
      tmp_string[i] = '0';
    }
  }
  return tmp_string;
}


x86 assembly (clang, -O0):
<strip_nonbinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c3 <strip_nonbinary+0x93>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     11b0 <strip_nonbinary+0x80>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
je     11b0 <strip_nonbinary+0x80>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    11b5 <strip_nonbinary+0x85>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <strip_nonbinary+0x2e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_nonbinary>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1185 <strip_nonbinary+0x55>
xor    %ebx,%ebx
jmp    1173 <strip_nonbinary+0x43>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1185 <strip_nonbinary+0x55>
movzbl (%r15,%rbx,1),%eax
and    $0xfe,%al
cmp    $0x30,%al
je     1160 <strip_nonbinary+0x30>
movb   $0x30,(%r15,%rbx,1)
jmp    1160 <strip_nonbinary+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strip_nonbinary(i8* %0) {
%2 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%3 = tail call i32 @strcpy(i8* %2, i8* %0)
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %14, %1
ret i8* %2
7: ; preds = %1, %14
%8 = phi i64 [ %15, %14 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = load i8, i8* %9
%11 = and i8 %10, -2
%12 = icmp eq i8 %11, 48
br i1 %12, label %14, label %13
13: ; preds = %7
store i8 48, i8* %9
br label %14
14: ; preds = %7, %13
%15 = add nuw nsw i64 %8, 1
%16 = tail call i32 @strlen(i8* %2)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %7, label %6
}