#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 ch_process(char const *);
char *strchr(char const *, char);
int ch_cmd_repeat(int crpt, int cidx, int eidx, const char **s_r) {
  char *p;
  int rc;
  if (crpt < 0)
    crpt = -crpt;
  p = strchr(*s_r, ')');
  if (p != NULL)
    *p = 0;
  rc = 1;
  while (rc && (--crpt >= 0))
    rc = ch_process(*s_r);
  if (p != NULL)
    *(p++) = ')';
  if (rc)
    *s_r = (const char *)p;
  return (rc);
}


x86 assembly (clang, -O0):
<ch_cmd_repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1147 <ch_cmd_repeat+0x27>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x29,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116e <ch_cmd_repeat+0x4e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     1196 <ch_cmd_repeat+0x76>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
setge  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11a6 <ch_cmd_repeat+0x86>
jmp    11ba <ch_cmd_repeat+0x9a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ch_process@plt>
mov    %eax,-0x24(%rbp)
jmp    1175 <ch_cmd_repeat+0x55>
cmpq   $0x0,-0x20(%rbp)
je     11d7 <ch_cmd_repeat+0xb7>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x29,(%rax)
cmpl   $0x0,-0x24(%rbp)
je     11ec <ch_cmd_repeat+0xcc>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ch_cmd_repeat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edi,%r15d
mov    %edi,%ebp
neg    %ebp
cmovs  %edi,%ebp
mov    (%rcx),%rdi
mov    $0x29,%esi
call   1030 <strchr@plt>
mov    %rax,%r14
test   %rax,%rax
je     114d <ch_cmd_repeat+0x2d>
movb   $0x0,(%r14)
test   %r15d,%r15d
je     119b <ch_cmd_repeat+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%rdi
call   1040 <ch_process@plt>
test   %eax,%eax
sete   %cl
je     1179 <ch_cmd_repeat+0x59>
lea    -0x1(%rbp),%edx
cmp    $0x1,%ebp
mov    %edx,%ebp
ja     1160 <ch_cmd_repeat+0x40>
test   %r14,%r14
je     11a7 <ch_cmd_repeat+0x87>
mov    %r14,%rdx
add    $0x1,%rdx
movb   $0x29,(%r14)
test   %cl,%cl
jne    1190 <ch_cmd_repeat+0x70>
mov    %rdx,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%eax
xor    %ecx,%ecx
test   %r14,%r14
jne    117e <ch_cmd_repeat+0x5e>
xor    %edx,%edx
test   %cl,%cl
je     118d <ch_cmd_repeat+0x6d>
jmp    1190 <ch_cmd_repeat+0x70>

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

LLVM IR (-O2):
define i32 @ch_cmd_repeat(i32 %0, i32 %1, i32 %2, i8** nocapture %3) {
%5 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%6 = load i8*, i8** %3
%7 = tail call i8* @strchr(i8* dereferenceable(1) %6, i8 signext 41)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %4
store i8 0, i8* %7
br label %10
10: ; preds = %9, %4
%11 = icmp eq i32 %0, 0
br i1 %11, label %21, label %12
12: ; preds = %10, %12
%13 = phi i32 [ %14, %12 ], [ %5, %10 ]
%14 = add nsw i32 %13, -1
%15 = load i8*, i8** %3
%16 = tail call i32 @ch_process(i8* %15)
%17 = icmp eq i32 %16, 0
%18 = xor i1 %17, true
%19 = icmp ugt i32 %13, 1
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %12, label %21
21: ; preds = %12, %10
%22 = phi i32 [ 1, %10 ], [ %16, %12 ]
%23 = phi i1 [ false, %10 ], [ %17, %12 ]
br i1 %8, label %26, label %24
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %7, i64 1
store i8 41, i8* %7
br label %26
26: ; preds = %24, %21
%27 = phi i8* [ %25, %24 ], [ null, %21 ]
br i1 %23, label %29, label %28
28: ; preds = %26
store i8* %27, i8** %3
br label %29
29: ; preds = %28, %26
ret i32 %22
}