#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void strrev(char *str) {
  char *temp = (char *)malloc(strlen(str) * sizeof(char));
  int i;
  strcpy(temp, str);
  for (i = 0; i <= strlen(str); i++) {
    str[i] = temp[strlen(str) - i - 1];
  }
  free(temp);
}


x86 assembly (clang, -O0):
<strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jg     11d2 <strrev+0x92>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <strrev+0x3a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
js     11ac <strrev+0x6c>
mov    $0xffffffff,%ebp
mov    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
cltq
movzbl (%r14,%rax,1),%eax
mov    %al,0x1(%r15,%rbx,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
add    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1180 <strrev+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @strrev(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %18, %8 ], [ 0, %1 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strlen(i8* %0)
%12 = xor i32 %10, -1
%13 = add i32 %11, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %16, i8* %17
%18 = add nuw nsw i64 %9, 1
%19 = tail call i32 @strlen(i8* %0)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %9, %20
br i1 %21, label %8, label %22
22: ; preds = %8, %1
%23 = tail call i32 @free(i8* %4)
ret void
}