#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 */
unsigned int strlen(char *);
void binary_sort(char *digits) {
  unsigned int n_digits;
  char *left;
  char *right;
  if (digits == NULL) {
    return;
  }
  n_digits = strlen(digits);
  if (n_digits == 0) {
    return;
  }
  left = digits;
  right = digits + n_digits;
  while (left <= right) {
    char temp;
    while (*left != '0') {
      left++;
    }
    while (*right != '1') {
      right--;
    }
    if (left >= right) {
      break;
    }
    temp = *left;
    *left = *right;
    *right = temp;
    left++;
    right--;
  }
}


x86 assembly (clang, -O0):
<binary_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <binary_sort+0x1c>
jmp    1205 <binary_sort+0xf5>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <binary_sort+0x37>
jmp    1205 <binary_sort+0xf5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     1205 <binary_sort+0xf5>
jmp    1170 <binary_sort+0x60>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     1191 <binary_sort+0x81>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1170 <binary_sort+0x60>
jmp    1196 <binary_sort+0x86>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
je     11b7 <binary_sort+0xa7>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1196 <binary_sort+0x86>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     11ca <binary_sort+0xba>
jmp    1205 <binary_sort+0xf5>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <binary_sort+0x4d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_sort>:
push   %rbx
test   %rdi,%rdi
je     116f <binary_sort+0x5f>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     116f <binary_sort+0x5f>
mov    %eax,%eax
add    %rbx,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x30,(%rbx)
lea    0x1(%rbx),%rbx
jne    1130 <binary_sort+0x20>
lea    -0x1(%rbx),%rcx
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x31,-0x1(%rax)
lea    -0x1(%rax),%rax
jne    1150 <binary_sort+0x40>
cmp    %rax,%rcx
jae    116f <binary_sort+0x5f>
movb   $0x31,-0x1(%rbx)
movb   $0x30,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
jbe    1130 <binary_sort+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @binary_sort(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
br label %61
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
br label %61
16: ; preds = %10
%17 = load i8*, i8** %2
store i8* %17, i8** %4
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8* %21, i8** %5
br label %22
22: ; preds = %49, %16
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = icmp ule i8* %23, %24
br i1 %25, label %26, label %61
26: ; preds = %22
br label %27
27: ; preds = %32, %26
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 48
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %4
br label %27
35: ; preds = %27
br label %36
36: ; preds = %41, %35
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 49
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %5
br label %36
44: ; preds = %36
%45 = load i8*, i8** %4
%46 = load i8*, i8** %5
%47 = icmp uge i8* %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
br label %61
49: ; preds = %44
%50 = load i8*, i8** %4
%51 = load i8, i8* %50
store i8 %51, i8* %6
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = load i8*, i8** %4
store i8 %53, i8* %54
%55 = load i8, i8* %6
%56 = load i8*, i8** %5
store i8 %55, i8* %56
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %4
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i32 -1
store i8* %60, i8** %5
br label %22
61: ; preds = %9, %15, %48, %22
ret void
}

LLVM IR (-O2):
define void @binary_sort(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %6, %24
%10 = phi i8* [ %16, %24 ], [ %0, %6 ]
%11 = phi i8* [ %21, %24 ], [ %8, %6 ]
br label %12
12: ; preds = %12, %9
%13 = phi i8* [ %16, %12 ], [ %10, %9 ]
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 48
%16 = getelementptr inbounds i8, i8* %13, i64 1
br i1 %15, label %17, label %12
17: ; preds = %12, %17
%18 = phi i8* [ %21, %17 ], [ %11, %12 ]
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 49
%21 = getelementptr inbounds i8, i8* %18, i64 -1
br i1 %20, label %22, label %17
22: ; preds = %17
%23 = icmp ult i8* %13, %18
br i1 %23, label %24, label %26
24: ; preds = %22
store i8 49, i8* %13
store i8 48, i8* %18
%25 = icmp ugt i8* %16, %21
br i1 %25, label %26, label %9
26: ; preds = %24, %22, %3, %1
ret void
}