#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 */
void increment(char *str, size_t len) {
  size_t index = len - 1;
  while (str[index] == '9')
    str[index--] = '0';
  str[index] = str[index] == 'X' ? '1' : (char)(str[index] + 1);
}


x86 assembly (clang, -O0):
<increment>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jne    1149 <increment+0x49>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x30,(%rax,%rcx,1)
jmp    1118 <increment+0x18>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    116b <increment+0x6b>
mov    $0x31,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <increment+0x80>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x1,%eax
movsbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
pop    %rbp
ret

x86 assembly (clang, -O2):
<increment>:
lea    (%rsi,%rdi,1),%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
cmp    $0x39,%cl
jne    1121 <increment+0x21>
movb   $0x30,(%rax)
add    $0xffffffffffffffff,%rax
jmp    1110 <increment+0x10>
cmp    $0x58,%cl
jne    112b <increment+0x2b>
mov    $0x31,%cl
mov    %cl,(%rax)
ret
add    $0x1,%cl
mov    %cl,(%rax)
ret

LLVM IR (-O0):
define void @increment(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = sub i64 %6, 1
store i64 %7, i64* %5
br label %8
8: ; preds = %15, %2
%9 = load i8*, i8** %3
%10 = load i64, i64* %5
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 57
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = load i64, i64* %5
%18 = add i64 %17, -1
store i64 %18, i64* %5
%19 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 48, i8* %19
br label %8
20: ; preds = %8
%21 = load i8*, i8** %3
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 88
br i1 %26, label %27, label %28
27: ; preds = %20
br label %37
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i64, i64* %5
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add nsw i32 %33, 1
%35 = trunc i32 %34 to i8
%36 = sext i8 %35 to i32
br label %37
37: ; preds = %28, %27
%38 = phi i32 [ 49, %27 ], [ %36, %28 ]
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %3
%41 = load i64, i64* %5
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8 %39, i8* %42
ret void
}

LLVM IR (-O2):
define void @increment(i8* nocapture %0, i64 %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i64 [ %1, %2 ], [ %5, %8 ]
%5 = add i64 %4, -1
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %9 [
i8 57, label %8
i8 88, label %11
]
8: ; preds = %3
store i8 48, i8* %6
br label %3
9: ; preds = %3
%10 = add i8 %7, 1
br label %11
11: ; preds = %3, %9
%12 = phi i8 [ %10, %9 ], [ 49, %3 ]
store i8 %12, i8* %6
ret void
}