#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*/ compare_strings(char *, char *);
char *doubles(char *);
int find_character(char *, char);
char *perform_operation(char *, char);
char *perform_addsub(char buffer[]) {
  char *string = buffer;
  int first_add, first_sub;
  do {
    buffer = string;
    string = doubles(buffer);
  } while (!compare_strings(buffer, string));
  do {
    buffer = string;
    first_add = find_character(buffer, '+');
    first_sub = find_character(buffer, '-');
    if (first_sub == 0)
      first_sub = -1;
    if ((first_add == -1) && (first_sub == -1))
      break;
    if (first_sub == -1)
      string = perform_operation(buffer, '+');
    else if (first_add = -1)
      string = perform_operation(buffer, '-');
    else if (first_add < first_sub)
      string = perform_operation(buffer, '+');
    else
      string = perform_operation(buffer, '-');
  } while (!compare_strings(buffer, string));
  return string;
}


x86 assembly (clang, -O0):
<perform_addsub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <doubles@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <compare_strings@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1154 <perform_addsub+0x14>
jmp    118b <perform_addsub+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
call   1030 <find_character@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <find_character@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11c6 <perform_addsub+0x86>
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11df <perform_addsub+0x9f>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11df <perform_addsub+0x9f>
jmp    128e <perform_addsub+0x14e>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1200 <perform_addsub+0xc0>
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
call   1050 <perform_operation@plt>
mov    %rax,-0x10(%rbp)
jmp    126c <perform_addsub+0x12c>
movl   $0xffffffff,-0x14(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    1216 <perform_addsub+0xd6>
jmp    122d <perform_addsub+0xed>
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <perform_operation@plt>
mov    %rax,-0x10(%rbp)
jmp    1267 <perform_addsub+0x127>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1250 <perform_addsub+0x110>
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
call   1050 <perform_operation@plt>
mov    %rax,-0x10(%rbp)
jmp    1262 <perform_addsub+0x122>
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <perform_operation@plt>
mov    %rax,-0x10(%rbp)
jmp    1267 <perform_addsub+0x127>
jmp    126c <perform_addsub+0x12c>
jmp    1271 <perform_addsub+0x131>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <compare_strings@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118b <perform_addsub+0x4b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perform_addsub>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%r14
mov    %rbx,%rdi
call   1040 <doubles@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <compare_strings@plt>
test   %eax,%eax
je     1150 <perform_addsub+0x10>
jmp    119b <perform_addsub+0x5b>
nop
xor    %ecx,%ecx
cmp    $0x2,%eax
setae  %cl
lea    (%rcx,%rcx,1),%esi
add    $0x2b,%esi
mov    %rbx,%rdi
call   1050 <perform_operation@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <compare_strings@plt>
mov    %r14,%rbx
test   %eax,%eax
jne    11c7 <perform_addsub+0x87>
mov    %rbx,%rdi
mov    $0x2b,%esi
call   1030 <find_character@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1030 <find_character@plt>
add    $0x1,%eax
cmp    $0xffffffff,%ebp
jne    1170 <perform_addsub+0x30>
cmp    $0x2,%eax
jae    1170 <perform_addsub+0x30>
mov    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @perform_addsub(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %3
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i8* @doubles(i8* %9)
store i8* %10, i8** %3
br label %11
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i8*, i8** %3
%14 = call i32 @compare_strings(i8* %12, i8* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %7, label %17
17: ; preds = %11
br label %18
18: ; preds = %57, %17
%19 = load i8*, i8** %3
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = call i32 @find_character(i8* %20, i8 signext 43)
store i32 %21, i32* %4
%22 = load i8*, i8** %2
%23 = call i32 @find_character(i8* %22, i8 signext 45)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 -1, i32* %5
br label %27
27: ; preds = %26, %18
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %30
br label %63
34: ; preds = %30, %27
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %2
%39 = call i8* @perform_operation(i8* %38, i8 signext 43)
store i8* %39, i8** %3
br label %56
40: ; preds = %34
store i32 -1, i32* %4
br i1 true, label %41, label %44
41: ; preds = %40
%42 = load i8*, i8** %2
%43 = call i8* @perform_operation(i8* %42, i8 signext 45)
store i8* %43, i8** %3
br label %55
44: ; preds = %40
%45 = load i32, i32* %4
%46 = load i32, i32* %5
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8*, i8** %2
%50 = call i8* @perform_operation(i8* %49, i8 signext 43)
store i8* %50, i8** %3
br label %54
51: ; preds = %44
%52 = load i8*, i8** %2
%53 = call i8* @perform_operation(i8* %52, i8 signext 45)
store i8* %53, i8** %3
br label %54
54: ; preds = %51, %48
br label %55
55: ; preds = %54, %41
br label %56
56: ; preds = %55, %37
br label %57
57: ; preds = %56
%58 = load i8*, i8** %2
%59 = load i8*, i8** %3
%60 = call i32 @compare_strings(i8* %58, i8* %59)
%61 = icmp ne i32 %60, 0
%62 = xor i1 %61, true
br i1 %62, label %18, label %63
63: ; preds = %57, %33
%64 = load i8*, i8** %3
ret i8* %64
}

LLVM IR (-O2):
define i8* @perform_addsub(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %4, %2 ]
%4 = tail call i8* @doubles(i8* %3)
%5 = tail call i32 @compare_strings(i8* %3, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %2, label %7
7: ; preds = %2, %15
%8 = phi i8* [ %17, %15 ], [ %4, %2 ]
%9 = tail call i32 @find_character(i8* %8, i8 signext 43)
%10 = tail call i32 @find_character(i8* %8, i8 signext 45)
%11 = icmp eq i32 %9, -1
%12 = add i32 %10, 1
%13 = icmp ult i32 %12, 2
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = select i1 %13, i8 43, i8 45
%17 = tail call i8* @perform_operation(i8* %8, i8 signext %16)
%18 = tail call i32 @compare_strings(i8* %8, i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %7, label %20
20: ; preds = %7, %15
%21 = phi i8* [ %8, %7 ], [ %17, %15 ]
ret i8* %21
}