#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 *);
int strlen(char *);
void revstr(char *str) {
  char *s, *e;
  int len;
  if ((len = strlen(str)) == 0)
    return;
  printf("revstr(%s) = ", str);
  s = str;
  e = str + len - 1;
  while (s < e) {
    char tmp = *s;
    *s = *e;
    *e = tmp;
    s++;
    e--;
  }
  printf("%s\n", str);
}


x86 assembly (clang, -O0):
<revstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1146 <revstr+0x26>
jmp    11ca <revstr+0xaa>
mov    -0x8(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ba <revstr+0x9a>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <revstr+0x51>
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<revstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     118f <revstr+0x6f>
mov    %eax,%ebp
lea    0xec7(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
movslq %ebp,%rax
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jbe    117c <revstr+0x5c>
lea    0x1(%r14),%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rcx),%edx
movzbl (%rax),%ebx
mov    %bl,-0x1(%rcx)
mov    %dl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     1160 <revstr+0x40>
lea    0xe8b(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"revstr(%s) = \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @revstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %39
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
store i8* %14, i8** %3
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8* %19, i8** %4
br label %20
20: ; preds = %24, %11
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = icmp ult i8* %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
store i8 %26, i8* %6
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = load i8*, i8** %3
store i8 %28, i8* %29
%30 = load i8, i8* %6
%31 = load i8*, i8** %4
store i8 %30, i8* %31
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %4
br label %20
36: ; preds = %20
%37 = load i8*, i8** %2
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %10
ret void
}

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