#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 reverse_string(char *given) {
  char *input = given;
  char *hare = input;
  char *head = input;
  char temp1;
  char temp2;
  while (1) {
    if (*(hare + 1) != '\0')
      hare++;
    else
      break;
  }
  while (1) {
    temp1 = (char)*head;
    temp2 = (char)*hare;
    *head = (char)temp2;
    *hare = (char)temp1;
    head++;
    hare--;
    if (head == hare)
      break;
  }
  printf("%s\n", input);
  return 0;
}


x86 assembly (clang, -O0):
<reverse_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1156 <reverse_string+0x46>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115b <reverse_string+0x4b>
jmp    1160 <reverse_string+0x50>
jmp    1134 <reverse_string+0x24>
jmp    1165 <reverse_string+0x55>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11b4 <reverse_string+0xa4>
jmp    11b9 <reverse_string+0xa9>
jmp    1165 <reverse_string+0x55>
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_string>:
push   %rax
mov    %rdi,%rsi
lea    -0x2(%rdi),%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x3(%rax)
lea    0x1(%rax),%rax
jne    1120 <reverse_string+0x10>
mov    %rsi,%rcx
nopl   (%rax)
movzbl (%rcx),%edi
movzbl 0x1(%rax),%edx
mov    %dl,(%rcx)
mov    %dil,0x1(%rax)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rcx,%rax
mov    %rdx,%rax
jne    1130 <reverse_string+0x20>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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