#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 *, ...);
int strlen(char *);
void reversestr(char str[]) {
  int first = 0;
  char temp;
  int lastchar = strlen(str);
  printf("Input string :: %s \n", str);
  printf("lastchar :: %d \n", lastchar);
  for (first; first < lastchar - 1; first++) {
    temp = str[first];
    str[first] = str[lastchar - 1];
    str[lastchar - 1] = temp;
    lastchar--;
  }
  printf("Input string currently :: %s \n", str);
}


x86 assembly (clang, -O0):
<reversestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c6 <reversestr+0xa6>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <reversestr+0x42>
mov    -0x8(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reversestr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0xecc(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     1182 <reversestr+0x62>
mov    %ebx,%eax
add    $0xfffffffffffffffe,%rax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%rcx,1),%edx
movzbl 0x1(%rbp,%rax,1),%ebx
mov    %bl,0x0(%rbp,%rcx,1)
mov    %dl,0x1(%rbp,%rax,1)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rax,%rcx
mov    %rdx,%rax
jl     1160 <reversestr+0x40>
lea    0xe9d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [21 x i8] c"Input string :: %s \0A\00"
@.str.1 = [17 x i8] c"lastchar :: %d \0A\00"
@.str.2 = [31 x i8] c"Input string currently :: %s \0A\00"
define void @reversestr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = zext i32 %2 to i64
%8 = add nsw i64 %7, -1
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %16, %9 ]
%11 = phi i64 [ %8, %6 ], [ %17, %9 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 %11
%15 = load i8, i8* %14
store i8 %15, i8* %12
store i8 %13, i8* %14
%16 = add nuw nsw i64 %10, 1
%17 = add nsw i64 %11, -1
%18 = icmp slt i64 %16, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret void
}