#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*/ reverseBytes(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void reverseFold(char *s) {
  reverseBytes(s, strlen(s));
  for (; *s; s++) {
    if (*s == '(')
      *s = ')';
    else if (*s == ')')
      *s = '(';
  }
}


x86 assembly (clang, -O0):
<reverseFold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x10(%rbp),%rdi
mov    %eax,%esi
call   1040 <reverseBytes@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a3 <reverseFold+0x83>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    1171 <reverseFold+0x51>
mov    -0x8(%rbp),%rax
movb   $0x29,(%rax)
jmp    118d <reverseFold+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
jne    1188 <reverseFold+0x68>
mov    -0x8(%rbp),%rax
movb   $0x28,(%rax)
jmp    118d <reverseFold+0x6d>
jmp    1192 <reverseFold+0x72>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1148 <reverseFold+0x28>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseFold>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <reverseBytes@plt>
jmp    1148 <reverseFold+0x28>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x28,%al
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x28,%al
je     1160 <reverseFold+0x40>
cmp    $0x29,%al
je     1140 <reverseFold+0x20>
test   %al,%al
jne    1144 <reverseFold+0x24>
jmp    1164 <reverseFold+0x44>
nopl   0x0(%rax)
mov    $0x29,%al
jmp    1142 <reverseFold+0x22>
pop    %rbx
ret

LLVM IR (-O0):
define void @reverseFold(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = call i32 @reverseBytes(i8* %3, i32 %5)
br label %7
7: ; preds = %27, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 40
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i8*, i8** %2
store i8 41, i8* %17
br label %26
18: ; preds = %11
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 41
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i8*, i8** %2
store i8 40, i8* %24
br label %25
25: ; preds = %23, %18
br label %26
26: ; preds = %25, %16
br label %27
27: ; preds = %26
%28 = load i8*, i8** %2
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %2
br label %7
30: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @reverseFold(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @reverseBytes(i8* %0, i32 %2)
br label %4
4: ; preds = %10, %1
%5 = phi i8* [ %0, %1 ], [ %11, %10 ]
%6 = load i8, i8* %5
switch i8 %6, label %10 [
i8 0, label %12
i8 40, label %8
i8 41, label %7
]
7: ; preds = %4
br label %8
8: ; preds = %4, %7
%9 = phi i8 [ 40, %7 ], [ 41, %4 ]
store i8 %9, i8* %5
br label %10
10: ; preds = %8, %4
%11 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
12: ; preds = %4
ret void
}