#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*/ getString(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *substStr(char *s) {
  char *lbracket, *rbracket;
  lbracket = strchr(s, '%');
  rbracket = strrchr(s, '%');
  if (lbracket && rbracket && lbracket != rbracket &&
      s[rbracket - lbracket + 1] == '\0') {
    strncpy(s, lbracket + 1, rbracket - lbracket - 1);
    s[rbracket - lbracket - 1] = '\0';
    getString(s);
  }
  return s;
}


x86 assembly (clang, -O0):
<substStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x25,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x25,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f3 <substStr+0xb3>
cmpq   $0x0,-0x18(%rbp)
je     11f3 <substStr+0xb3>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11f3 <substStr+0xb3>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11f3 <substStr+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <getString@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substStr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0x25,%esi
call   1050 <strchr@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x25,%esi
call   1060 <strrchr@plt>
test   %r14,%r14
je     11a0 <substStr+0x60>
mov    %rax,%rbx
test   %rax,%rax
je     11a0 <substStr+0x60>
cmp    %rbx,%r14
je     11a0 <substStr+0x60>
sub    %r14,%rbx
cmpb   $0x0,0x1(%rbx,%r15,1)
jne    11a0 <substStr+0x60>
add    $0x1,%r14
lea    -0x1(%rbx),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
movb   $0x0,-0x1(%r15,%rbx,1)
mov    %r15,%rdi
call   1030 <getString@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @substStr(i8* returned %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 37)
%4 = icmp eq i8* %2, null
%5 = icmp eq i8* %3, null
%6 = select i1 %4, i1 true, i1 %5
%7 = icmp eq i8* %2, %3
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %24, label %9
9: ; preds = %1
%10 = ptrtoint i8* %3 to i64
%11 = ptrtoint i8* %2 to i64
%12 = sub i64 %10, %11
%13 = add nsw i64 %12, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %2, i64 1
%19 = add nsw i64 %12, -1
%20 = trunc i64 %19 to i32
%21 = tail call i32 @strncpy(i8* %0, i8* %18, i32 %20)
%22 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %22
%23 = tail call i32 @getString(i8* %0)
br label %24
24: ; preds = %17, %9, %1
ret i8* %0
}