#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*/ printf(char *, char);
long strlen(char *);
int increment(char a[]) {
  long len = strlen(a);
  len--;
  do {
    printf("a[len]=%c ", a[len]);
    if (a[len] != '9') {
      a[len] += 1;
      printf("a[len]=%c ", a[len]);
      return 0;
    } else {
      printf("a[len]=%c ", a[len]);
      a[len--] = '0';
    }
  } while (1);
}


x86 assembly (clang, -O0):
<increment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xeac(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
je     11a8 <increment+0x88>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
add    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xe6d(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11eb <increment+0xcb>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xe49(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x30,(%rax,%rcx,1)
jmp    11dc <increment+0xbc>
mov    $0x1,%al
test   $0x1,%al
jne    1145 <increment+0x25>
jmp    11eb <increment+0xcb>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<increment>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r14
lea    (%rax,%r15,1),%rbx
add    $0xffffffffffffffff,%rbx
movsbl -0x1(%rax,%r15,1),%esi
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1(%r14,%r15,1),%al
cmp    $0x39,%al
jne    118d <increment+0x6d>
lea    0xea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x39,%esi
call   1040 <printf@plt>
movb   $0x30,(%rbx)
lea    -0x1(%rbx),%r15
movsbl -0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl -0x1(%rbx),%eax
mov    %r15,%rbx
cmp    $0x39,%al
je     1160 <increment+0x40>
jmp    1190 <increment+0x70>
mov    %rbx,%r15
add    $0x1,%al
mov    %al,(%r15)
movsbl %al,%esi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"a[len]=%c \00"
define i32 @increment(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strlen(i8* %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = add nsw i64 %7, -1
store i64 %8, i64* %4
br label %9
9: ; preds = %45, %1
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = load i8*, i8** %3
%16 = load i64, i64* %4
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 57
br i1 %20, label %21, label %34
21: ; preds = %9
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, 1
%28 = trunc i32 %27 to i8
store i8 %28, i8* %24
%29 = load i8*, i8** %3
%30 = load i64, i64* %4
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %32)
store i32 0, i32* %2
br label %46
34: ; preds = %9
%35 = load i8*, i8** %3
%36 = load i64, i64* %4
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %38)
%40 = load i8*, i8** %3
%41 = load i64, i64* %4
%42 = add nsw i64 %41, -1
store i64 %42, i64* %4
%43 = getelementptr inbounds i8, i8* %40, i64 %41
store i8 48, i8* %43
br label %44
44: ; preds = %34
br label %45
45: ; preds = %44
br i1 true, label %9, label %46
46: ; preds = %21, %45
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@.str = [11 x i8] c"a[len]=%c \00"
define i32 @increment(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, -1
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 57
br i1 %8, label %14, label %9
9: ; preds = %14, %1
%10 = phi i8* [ %4, %1 ], [ %19, %14 ]
%11 = phi i8 [ %7, %1 ], [ %22, %14 ]
%12 = add i8 %11, 1
store i8 %12, i8* %10
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %12)
ret i32 0
14: ; preds = %1, %14
%15 = phi i8* [ %19, %14 ], [ %4, %1 ]
%16 = phi i64 [ %18, %14 ], [ %3, %1 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext 57)
store i8 48, i8* %15
%18 = add nsw i64 %16, -1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %20)
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 57
br i1 %23, label %14, label %9
}