#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 */
long binaryToDecimal(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ invert(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
long reverseOnesComplement(int size, char binaryIn[size]) {
  if (binaryIn[0] == '0')
    return binaryToDecimal(0, size, binaryIn);
  char inverse[size];
  strcpy(inverse, binaryIn);
  invert(0, size, inverse);
  long result = binaryToDecimal(0, size, inverse);
  result *= -1;
  return result;
}


x86 assembly (clang, -O0):
<reverseOnesComplement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1166 <reverseOnesComplement+0x36>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
call   1050 <binaryToDecimal@plt>
mov    %rax,-0x8(%rbp)
jmp    11cd <reverseOnesComplement+0x9d>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdx
mov    -0xc(%rbp),%esi
xor    %edi,%edi
call   1030 <invert@plt>
mov    -0x38(%rbp),%rdx
mov    -0xc(%rbp),%esi
xor    %edi,%edi
call   1050 <binaryToDecimal@plt>
mov    %rax,-0x30(%rbp)
imul   $0xffffffffffffffff,-0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseOnesComplement>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rdx
mov    %edi,%r14d
cmpb   $0x30,(%rsi)
jne    1159 <reverseOnesComplement+0x29>
xor    %edi,%edi
mov    %r14d,%esi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <binaryToDecimal@plt>
mov    %rsp,%r15
mov    %r14d,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rdx,%rsi
call   1040 <strcpy@plt>
xor    %edi,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1030 <invert@plt>
xor    %edi,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1050 <binaryToDecimal@plt>
neg    %rax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @reverseOnesComplement(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 48
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* %4
%18 = load i8*, i8** %5
%19 = call i64 @binaryToDecimal(i32 0, i32 %17, i8* %18)
store i64 %19, i64* %3
br label %35
20: ; preds = %2
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %6
%24 = alloca i8, i64 %22
store i64 %22, i64* %7
%25 = load i8*, i8** %5
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i32, i32* %4
%28 = call i32 @invert(i32 0, i32 %27, i8* %24)
%29 = load i32, i32* %4
%30 = call i64 @binaryToDecimal(i32 0, i32 %29, i8* %24)
store i64 %30, i64* %8
%31 = load i64, i64* %8
%32 = mul nsw i64 %31, -1
store i64 %32, i64* %8
%33 = load i64, i64* %8
store i64 %33, i64* %3
%34 = load i8*, i8** %6
br label %35
35: ; preds = %20, %16
%36 = load i64, i64* %3
ret i64 %36
}

LLVM IR (-O2):
define i64 @reverseOnesComplement(i32 %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 48
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i64 @binaryToDecimal(i32 0, i32 %0, i8* %1)
br label %15
7: ; preds = %2
%8 = zext i32 %0 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = call i32 @strcpy(i8* %10, i8* %1)
%12 = call i32 @invert(i32 0, i32 %0, i8* %10)
%13 = call i64 @binaryToDecimal(i32 0, i32 %0, i8* %10)
%14 = sub nsw i64 0, %13
br label %15
15: ; preds = %7, %5
%16 = phi i64 [ %6, %5 ], [ %14, %7 ]
ret i64 %16
}