#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 *);
void reverse(char *string) {
  char back[256];
  int i, length = strlen(string) - 1;
  for (i = length; i >= 0; i--)
    back[length - i] = string[i];
  strcpy(string, back);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x118(%rbp)
mov    -0x118(%rbp),%eax
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jl     1191 <reverse+0x71>
mov    -0x8(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x118(%rbp),%eax
sub    -0x114(%rbp),%eax
cltq
mov    %cl,-0x110(%rbp,%rax,1)
mov    -0x114(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x114(%rbp)
jmp    114d <reverse+0x2d>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
jle    12a5 <reverse+0x185>
lea    -0x1(%rax),%r8d
mov    %eax,%r9d
cmp    $0x8,%eax
jae    114c <reverse+0x2c>
mov    %r9,%rsi
jmp    1272 <reverse+0x152>
cmp    $0x20,%eax
jae    1158 <reverse+0x38>
xor    %eax,%eax
jmp    1210 <reverse+0xf0>
mov    %r9d,%eax
and    $0xffffffe0,%eax
lea    (%r9,%rbx,1),%rsi
add    $0xfffffffffffffff0,%rsi
mov    %r8,%rcx
sub    %r9,%rcx
mov    %rsp,%rdx
lea    (%rcx,%rdx,1),%rdi
add    $0x11,%rdi
xor    %ecx,%ecx
pxor   %xmm0,%xmm0
nopl   (%rax)
movdqu -0x10(%rsi),%xmm1
movdqu (%rsi),%xmm2
movdqa %xmm2,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm2
pshufd $0x4e,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqu %xmm2,-0x10(%rdi,%rcx,1)
movdqu %xmm1,(%rdi,%rcx,1)
add    $0x20,%rcx
add    $0xffffffffffffffe0,%rsi
cmp    %rcx,%rax
jne    1180 <reverse+0x60>
cmp    %r9,%rax
je     12a5 <reverse+0x185>
test   $0x18,%r9b
je     12b9 <reverse+0x199>
mov    %r9d,%ecx
and    $0xfffffff8,%ecx
mov    %r9d,%esi
and    $0x7,%esi
mov    %r9,%rdx
sub    %rax,%rdx
lea    (%rbx,%rdx,1),%rdi
add    $0xfffffffffffffff8,%rdi
mov    %r8,%r10
sub    %r9,%r10
mov    %rsp,%rdx
add    %r10,%rdx
add    $0x1,%rdx
pxor   %xmm0,%xmm0
xchg   %ax,%ax
movq   (%rdi),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%rdx,%rax,1)
add    $0x8,%rax
add    $0xfffffffffffffff8,%rdi
cmp    %rax,%rcx
jne    1240 <reverse+0x120>
cmp    %r9,%rcx
je     12a5 <reverse+0x185>
sub    %rsi,%r8
add    $0x1,%rsi
mov    %rsp,%rax
add    %r8,%rax
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl -0x2(%rbx,%rsi,1),%ecx
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rsi
add    $0x1,%rax
cmp    $0x1,%rsi
ja     1290 <reverse+0x170>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
add    $0x100,%rsp
pop    %rbx
ret
and    $0x1f,%r9d
jmp    1144 <reverse+0x24>

LLVM IR (-O0):
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %5
%9 = load i32, i32* %5
store i32 %9, i32* %4
br label %10
10: ; preds = %24, %1
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = sub nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %22
store i8 %18, i8* %23
br label %24
24: ; preds = %13
%25 = load i32, i32* %4
%26 = add nsw i32 %25, -1
store i32 %26, i32* %4
br label %10
27: ; preds = %10
%28 = load i8*, i8** %2
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%30 = call i32 @strcpy(i8* %28, i8* %29)
ret void
}

LLVM IR (-O2):
define void @reverse(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %72
6: ; preds = %1
%7 = add nsw i32 %4, -1
%8 = zext i32 %4 to i64
%9 = zext i32 %7 to i64
%10 = icmp ult i32 %4, 8
br i1 %10, label %62, label %11
11: ; preds = %6
%12 = icmp ult i32 %4, 32
br i1 %12, label %42, label %13
13: ; preds = %11
%14 = and i64 %8, 4294967264
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %34, %15 ]
%17 = xor i64 %16, -1
%18 = add i64 %17, %8
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -15
%21 = bitcast i8* %20 to <16 x i8>*
%22 = load <16 x i8>, <16 x i8>* %21
%23 = shufflevector <16 x i8> %22, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%24 = getelementptr inbounds i8, i8* %19, i64 -16
%25 = getelementptr inbounds i8, i8* %24, i64 -15
%26 = bitcast i8* %25 to <16 x i8>*
%27 = load <16 x i8>, <16 x i8>* %26
%28 = shufflevector <16 x i8> %27, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%29 = sub nuw nsw i64 %9, %18
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %29
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %23, <16 x i8>* %31
%32 = getelementptr inbounds i8, i8* %30, i64 16
%33 = bitcast i8* %32 to <16 x i8>*
store <16 x i8> %28, <16 x i8>* %33
%34 = add nuw i64 %16, 32
%35 = icmp eq i64 %34, %14
br i1 %35, label %36, label %15
36: ; preds = %15
%37 = icmp eq i64 %14, %8
br i1 %37, label %72, label %38
38: ; preds = %36
%39 = and i64 %8, 31
%40 = and i64 %8, 24
%41 = icmp eq i64 %40, 0
br i1 %41, label %62, label %42
42: ; preds = %11, %38
%43 = phi i64 [ %14, %38 ], [ 0, %11 ]
%44 = and i64 %8, 4294967288
%45 = and i64 %8, 7
%46 = getelementptr inbounds i8, i8* %0, i64 -7
br label %47
47: ; preds = %47, %42
%48 = phi i64 [ %43, %42 ], [ %58, %47 ]
%49 = xor i64 %48, -1
%50 = add i64 %49, %8
%51 = getelementptr inbounds i8, i8* %46, i64 %50
%52 = bitcast i8* %51 to <8 x i8>*
%53 = load <8 x i8>, <8 x i8>* %52
%54 = shufflevector <8 x i8> %53, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%55 = sub nuw nsw i64 %9, %50
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %55
%57 = bitcast i8* %56 to <8 x i8>*
store <8 x i8> %54, <8 x i8>* %57
%58 = add nuw i64 %48, 8
%59 = icmp eq i64 %58, %44
br i1 %59, label %60, label %47
60: ; preds = %47
%61 = icmp eq i64 %44, %8
br i1 %61, label %72, label %62
62: ; preds = %6, %38, %60
%63 = phi i64 [ %8, %6 ], [ %39, %38 ], [ %45, %60 ]
br label %64
64: ; preds = %62, %64
%65 = phi i64 [ %66, %64 ], [ %63, %62 ]
%66 = add nsw i64 %65, -1
%67 = getelementptr inbounds i8, i8* %0, i64 %66
%68 = load i8, i8* %67
%69 = sub nuw nsw i64 %9, %66
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %69
store i8 %68, i8* %70
%71 = icmp ugt i64 %65, 1
br i1 %71, label %64, label %72
72: ; preds = %64, %36, %60, %1
%73 = call i32 @strcpy(i8* %0, i8* %3)
ret void
}