#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 */
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char *);
void next_str(char *str, const char *begin, const char *end, char low,
              char high) {
  size_t len;
  char *p;
  if (strcmp(str, end) == 0) {
    strcpy(str, begin);
    return;
  }
  len = strlen(str);
  for (p = str + len - 1; p + 1 != str; --p)
    if (*p == high)
      *p = low;
    else {
      ++*p;
      break;
    }
}


x86 assembly (clang, -O0):
<next_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1176 <next_str+0x46>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11ec <next_str+0xbc>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
cmp    -0x8(%rbp),%rax
je     11ec <next_str+0xbc>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jne    11c6 <next_str+0x96>
mov    -0x19(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
jmp    11d6 <next_str+0xa6>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
jmp    11ec <next_str+0xbc>
jmp    11db <next_str+0xab>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1193 <next_str+0x63>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1177 <next_str+0x47>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1193 <next_str+0x63>
nopl   (%rax)
movzbl -0x1(%rbx,%rax,1),%ecx
cmp    %bpl,%cl
jne    118c <next_str+0x5c>
mov    %r14b,-0x1(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1160 <next_str+0x30>
jmp    1193 <next_str+0x63>
mov    %rbx,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>
add    $0x1,%cl
mov    %cl,-0x1(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @next_str(i8* %0, i8* %1, i8* %2, i8 signext %3, i8 signext %4) {
%6 = tail call i64 @strcmp(i8* %0, i8* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %24
10: ; preds = %5
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %0, i64 %11
br label %15
15: ; preds = %13, %20
%16 = phi i8* [ %17, %20 ], [ %14, %13 ]
%17 = getelementptr inbounds i8, i8* %16, i64 -1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, %4
br i1 %19, label %20, label %22
20: ; preds = %15
store i8 %3, i8* %17
%21 = icmp eq i8* %17, %0
br i1 %21, label %24, label %15
22: ; preds = %15
%23 = add i8 %18, 1
store i8 %23, i8* %17
br label %24
24: ; preds = %20, %10, %22, %8
ret void
}