#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);
unsigned int strlen(char *);
char *binaryAddition(char *binary_1) {
  unsigned int i = 0;
  unsigned int length_1, length_2;
  unsigned int length;
  char *res;
  unsigned int carry = 1;
  res = malloc(sizeof(*res) + 32);
  length = strlen(binary_1);
  while ((binary_1[length - (i + 1)] == '1') && (carry == 1)) {
    binary_1[length - (i + 1)] = '0';
    carry = 1;
    i++;
  }
  binary_1[length - (i + 1)] = '1';
  carry = 0;
  return binary_1;
}


x86 assembly (clang, -O0):
<binaryAddition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x24(%rbp)
mov    $0x21,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0xc(%rbp),%edx
add    $0x1,%edx
sub    %edx,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x31,%ecx
mov    %al,-0x25(%rbp)
jne    1181 <binaryAddition+0x61>
cmpl   $0x1,-0x24(%rbp)
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1191 <binaryAddition+0x71>
jmp    11bb <binaryAddition+0x9b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0xc(%rbp),%edx
add    $0x1,%edx
sub    %edx,%ecx
mov    %ecx,%ecx
movb   $0x30,(%rax,%rcx,1)
movl   $0x1,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1154 <binaryAddition+0x34>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0xc(%rbp),%edx
add    $0x1,%edx
sub    %edx,%ecx
mov    %ecx,%ecx
movb   $0x31,(%rax,%rcx,1)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binaryAddition>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    -0x1(%rax),%edx
lea    (%rbx,%rdx,1),%rcx
cmpb   $0x31,(%rbx,%rdx,1)
jne    1142 <binaryAddition+0x32>
add    $0xfffffffe,%eax
nopl   0x0(%rax)
movb   $0x30,(%rcx)
mov    %eax,%edx
lea    (%rbx,%rdx,1),%rcx
add    $0xffffffff,%eax
cmpb   $0x31,(%rbx,%rdx,1)
je     1130 <binaryAddition+0x20>
movb   $0x31,(%rcx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @binaryAddition(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 1, i32* %8
%9 = call i8* @malloc(i32 33)
store i8* %9, i8** %7
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
br label %12
12: ; preds = %28, %1
%13 = load i8*, i8** %2
%14 = load i32, i32* %6
%15 = load i32, i32* %3
%16 = add i32 %15, 1
%17 = sub i32 %14, %16
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 49
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 1
br label %26
26: ; preds = %23, %12
%27 = phi i1 [ false, %12 ], [ %25, %23 ]
br i1 %27, label %28, label %38
28: ; preds = %26
%29 = load i8*, i8** %2
%30 = load i32, i32* %6
%31 = load i32, i32* %3
%32 = add i32 %31, 1
%33 = sub i32 %30, %32
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %29, i64 %34
store i8 48, i8* %35
store i32 1, i32* %8
%36 = load i32, i32* %3
%37 = add i32 %36, 1
store i32 %37, i32* %3
br label %12
38: ; preds = %26
%39 = load i8*, i8** %2
%40 = load i32, i32* %6
%41 = load i32, i32* %3
%42 = add i32 %41, 1
%43 = sub i32 %40, %42
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %39, i64 %44
store i8 49, i8* %45
store i32 0, i32* %8
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
define i8* @binaryAddition(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, -1
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 49
br i1 %7, label %8, label %17
8: ; preds = %1, %8
%9 = phi i8* [ %14, %8 ], [ %5, %1 ]
%10 = phi i32 [ %11, %8 ], [ 1, %1 ]
store i8 48, i8* %9
%11 = add i32 %10, 1
%12 = sub i32 %2, %11
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 49
br i1 %16, label %8, label %17
17: ; preds = %8, %1
%18 = phi i8* [ %5, %1 ], [ %14, %8 ]
store i8 49, i8* %18
ret i8* %0
}