#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=%s ", a);
    if (a[len] != '9') {
      a[len] += 1;
      printf("a=%s ", a);
      return 0;
    } else {
      printf("a=%s ", a);
      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),%rsi
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
je     1198 <increment+0x78>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
add    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <increment+0xb3>
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdi
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    11c4 <increment+0xa4>
mov    $0x1,%al
test   $0x1,%al
jne    1145 <increment+0x25>
jmp    11d3 <increment+0xb3>
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    0xec9(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    (%r14,%r15,1),%rbx
add    $0xffffffffffffffff,%rbx
mov    -0x1(%r14,%r15,1),%al
cmp    $0x39,%al
jne    1185 <increment+0x65>
lea    0xea9(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
movb   $0x30,(%rbx)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
movzbl -0x1(%rbx),%eax
add    $0xffffffffffffffff,%rbx
cmp    $0x39,%al
je     1160 <increment+0x40>
add    $0x1,%al
mov    %al,(%rbx)
lea    0xe70(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"a=%s \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 = %36, %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 57
br i1 %17, label %18, label %28
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 1
%25 = trunc i32 %24 to i8
store i8 %25, i8* %21
%26 = load i8*, i8** %3
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 0, i32* %2
br label %37
28: ; preds = %9
%29 = load i8*, i8** %3
%30 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = add nsw i64 %32, -1
store i64 %33, i64* %4
%34 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 48, i8* %34
br label %35
35: ; preds = %28
br label %36
36: ; preds = %35
br i1 true, label %9, label %37
37: ; preds = %18, %36
%38 = load i32, i32* %2
ret i32 %38
}

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