#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 *skip_to_next_curly(char const *);
char *strchr(char const *, char);
const char *skip_over_curlies(const char *buf) {
  const char *p;
  int opened;
  p = strchr(buf, '{');
  if (!p)
    return buf;
  ++p;
  opened = 1;
  while (opened) {
    p = skip_to_next_curly(p);
    if (!p)
      return 0;
    if (*p == '{')
      ++opened;
    else if (*p == '}')
      --opened;
    ++p;
  }
  return p;
}


x86 assembly (clang, -O0):
<skip_over_curlies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x7b,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <skip_over_curlies+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <skip_over_curlies+0xcd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e5 <skip_over_curlies+0xc5>
mov    -0x18(%rbp),%rdi
call   1040 <skip_to_next_curly@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <skip_over_curlies+0x78>
movq   $0x0,-0x8(%rbp)
jmp    11ed <skip_over_curlies+0xcd>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    11b6 <skip_over_curlies+0x96>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d4 <skip_over_curlies+0xb4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7d,%eax
jne    11cf <skip_over_curlies+0xaf>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d4 <skip_over_curlies+0xb4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1169 <skip_over_curlies+0x49>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_over_curlies>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x7b,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117d <skip_over_curlies+0x5d>
add    $0x1,%rax
mov    $0x1,%ebp
mov    %rax,%rbx
jmp    115b <skip_over_curlies+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebp
add    $0x1,%rbx
test   %ebp,%ebp
je     117d <skip_over_curlies+0x5d>
mov    %rbx,%rdi
call   1040 <skip_to_next_curly@plt>
test   %rax,%rax
je     117b <skip_over_curlies+0x5b>
mov    %rax,%rbx
movzbl (%rax),%eax
cmp    $0x7d,%al
je     1150 <skip_over_curlies+0x30>
cmp    $0x7b,%al
jne    1153 <skip_over_curlies+0x33>
add    $0x1,%ebp
jmp    1153 <skip_over_curlies+0x33>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @skip_over_curlies(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 123)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
store i8* %11, i8** %2
br label %46
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
store i32 1, i32* %5
br label %15
15: ; preds = %41, %12
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %44
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = call i8* @skip_to_next_curly(i8* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
store i8* null, i8** %2
br label %46
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 123
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %41
32: ; preds = %24
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 125
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %5
%39 = add nsw i32 %38, -1
store i32 %39, i32* %5
br label %40
40: ; preds = %37, %32
br label %41
41: ; preds = %40, %29
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
br label %15
44: ; preds = %15
%45 = load i8*, i8** %4
store i8* %45, i8** %2
br label %46
46: ; preds = %44, %23, %10
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
define i8* @skip_over_curlies(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 123)
%3 = icmp eq i8* %2, null
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
br label %6
6: ; preds = %4, %17
%7 = phi i8* [ %5, %4 ], [ %19, %17 ]
%8 = phi i32 [ 1, %4 ], [ %18, %17 ]
%9 = tail call i8* @skip_to_next_curly(i8* %7)
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = load i8, i8* %9
switch i8 %12, label %17 [
i8 123, label %13
i8 125, label %15
]
13: ; preds = %11
%14 = add nsw i32 %8, 1
br label %17
15: ; preds = %11
%16 = add nsw i32 %8, -1
br label %17
17: ; preds = %11, %15, %13
%18 = phi i32 [ %14, %13 ], [ %16, %15 ], [ %8, %11 ]
%19 = getelementptr inbounds i8, i8* %9, i64 1
%20 = icmp eq i32 %18, 0
br i1 %20, label %21, label %6
21: ; preds = %17, %6, %1
%22 = phi i8* [ %0, %1 ], [ %19, %17 ], [ null, %6 ]
ret i8* %22
}