#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 */
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ swap(char *, char *);
char *reverse(char *str) {
  char *str2 = malloc(sizeof(char) * 100);
  strcpy(str2, str);
  int len = 0;
  while (str2[len] != 0) {
    len++;
  }
  int i = 0;
  while (i < len / 2) {
    swap(&str2[i], &str2[len - i - 1]);
    i++;
  }
  return str2;
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1181 <reverse+0x51>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <reverse+0x2e>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11d6 <reverse+0xa6>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <reverse+0x58>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0xffffffffffffffff,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%r14,%rax,1)
lea    0x1(%rax),%rax
jne    1160 <reverse+0x30>
test   $0xfffffffe,%eax
je     11a9 <reverse+0x79>
movslq %eax,%r12
lea    (%r14,%r12,1),%r15
add    $0xffffffffffffffff,%r15
shr    %r12d
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <swap@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
add    $0xffffffffffffffff,%r12
jne    1190 <reverse+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 100)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = load i8*, i8** %2
%9 = call i32 @strcpy(i8* %7, i8* %8)
store i32 0, i32* %4
br label %10
10: ; preds = %18, %1
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %10
21: ; preds = %10
store i32 0, i32* %5
br label %22
22: ; preds = %27, %21
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = sdiv i32 %24, 2
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %42
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8*, i8** %3
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = sub nsw i32 %33, %34
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %32, i64 %37
%39 = call i32 @swap(i8* %31, i8* %38)
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %22
42: ; preds = %22
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
define i8* @reverse(i8* %0) {
%2 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%3 = tail call i32 @strcpy(i8* %2, i8* %0)
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %9, %4 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = and i64 %5, 4294967294
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = lshr i64 %5, 1
%15 = shl i64 %5, 32
%16 = ashr exact i64 %15, 32
%17 = and i64 %14, 2147483647
br label %18
18: ; preds = %13, %18
%19 = phi i64 [ 0, %13 ], [ %25, %18 ]
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = xor i64 %19, -1
%22 = add nsw i64 %16, %21
%23 = getelementptr inbounds i8, i8* %2, i64 %22
%24 = tail call i32 @swap(i8* %20, i8* %23)
%25 = add nuw nsw i64 %19, 1
%26 = icmp eq i64 %25, %17
br i1 %26, label %27, label %18
27: ; preds = %18, %10
ret i8* %2
}