#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);
void reverse(char *str) {
  int length = 0;
  while (*str++)
    length++;
  printf("uzunluk: %d\n", length);
  while (length-- >= 0)
    printf("%c", *(--str));
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
cmpb   $0x0,(%rax)
je     1149 <reverse+0x39>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <reverse+0x13>
mov    -0xc(%rbp),%eax
lea    0xead(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jl     1193 <reverse+0x83>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
lea    0xe88(%rip),%rdi
movsbl -0x1(%rax),%esi
call   1030 <printf@plt>
jmp    115b <reverse+0x4b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <reverse+0x10>
lea    -0x1(%rbx),%eax
movsbl %al,%esi
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
lea    0xec9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbx
test   %ebx,%ebx
jg     1150 <reverse+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"uzunluk: %d\0A\00"
@.str.1 = [3 x i8] c"%c\00"
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %2
%7 = load i8, i8* %5
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
br label %4
12: ; preds = %4
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %14)
br label %16
16: ; preds = %20, %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
%19 = icmp sge i32 %17, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %2
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %23)
br label %16
25: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"uzunluk: %d\0A\00"
@.str.1 = [3 x i8] c"%c\00"
define void @reverse(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %5, %2 ]
%4 = phi i32 [ 0, %1 ], [ %8, %2 ]
%5 = getelementptr inbounds i8, i8* %3, i64 1
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
%8 = add nuw nsw i32 %4, 1
br i1 %7, label %9, label %2
9: ; preds = %2
%10 = trunc i32 %4 to i8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 signext %10)
br label %12
12: ; preds = %9, %12
%13 = phi i32 [ %15, %12 ], [ %4, %9 ]
%14 = phi i8* [ %16, %12 ], [ %5, %9 ]
%15 = add nsw i32 %13, -1
%16 = getelementptr inbounds i8, i8* %14, i64 -1
%17 = load i8, i8* %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %17)
%19 = icmp sgt i32 %13, 0
br i1 %19, label %12, label %20
20: ; preds = %12
ret void
}