#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*/ strcpy(char *, char *);
int strlen(char *);
char *str_rev(char *t, char *s) {
  char p;
  int i, j;
  i = strlen(s);
  strcpy(t, s);
  for (j = 0; j < strlen(s) / 2; j++, i--) {
    p = s[j];
    s[j] = s[i - 1];
    s[i - 1] = p;
  }
  strcpy(t, s);
  return t;
}


x86 assembly (clang, -O0):
<str_rev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11c7 <str_rev+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <str_rev+0x30>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_rev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1191 <str_rev+0x71>
movslq %ebp,%rax
lea    (%rax,%r15,1),%rbp
add    $0xffffffffffffffff,%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
movzbl 0x0(%rbp),%ecx
mov    %cl,(%r15,%rbx,1)
mov    %al,0x0(%rbp)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0xffffffffffffffff,%rbp
cmp    %rax,%rbx
jl     1160 <str_rev+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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