#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void revstr(char *str) {
  char *p, *s;
  int i;
  int size;
  if ((size = strlen(str)) == 0)
    return;
  p = (char *)calloc(size + 1, sizeof(char));
  s = p;
  for (i = size; i > 0; i--, s++)
    *s = *(str + i - 1);
  *s = '\0';
  memset(str, 0, size);
  strncpy(str, p, size);
  free(p);
}


x86 assembly (clang, -O0):
<revstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1176 <revstr+0x26>
jmp    11fc <revstr+0xac>
mov    -0x20(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11ce <revstr+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    -0x1(%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1198 <revstr+0x48>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<revstr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
test   %eax,%eax
je     11ba <revstr+0x6a>
mov    %eax,%r14d
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11c0 <revstr+0x70>
mov    %r14d,%r9d
cmp    $0x20,%r14d
jb     1195 <revstr+0x45>
lea    (%rbx,%r9,1),%rax
cmp    %r15,%rax
jbe    11c8 <revstr+0x78>
lea    (%r15,%r9,1),%rax
cmp    %rbx,%rax
jbe    11c8 <revstr+0x78>
mov    %r9,%rax
mov    %r15,%rcx
add    $0x1,%rax
nop
movzbl -0x2(%rbx,%rax,1),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     11a0 <revstr+0x50>
jmp    1286 <revstr+0x136>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rcx
jmp    1286 <revstr+0x136>
mov    %r9d,%r8d
and    $0xffffffe0,%r8d
mov    %r9d,%eax
and    $0x1f,%eax
lea    (%r15,%r8,1),%rcx
mov    %r15,%rdi
add    $0x10,%rdi
mov    %r8,%r10
neg    %r10
lea    (%r9,%rbx,1),%rdx
add    $0xfffffffffffffff0,%rdx
xor    %esi,%esi
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu -0x10(%rdx,%rsi,1),%xmm1
movdqu (%rdx,%rsi,1),%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)
movdqu %xmm1,(%rdi)
add    $0x20,%rdi
add    $0xffffffffffffffe0,%rsi
cmp    %rsi,%r10
jne    1200 <revstr+0xb0>
cmp    %r9,%r8
jne    119b <revstr+0x4b>
movb   $0x0,(%rcx)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @revstr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %60, label %4
4: ; preds = %1
%5 = add nsw i32 %2, 1
%6 = tail call i64 @calloc(i32 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %55
9: ; preds = %4
%10 = zext i32 %2 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 -1
%12 = icmp ult i32 %2, 32
br i1 %12, label %44, label %13
13: ; preds = %9
%14 = getelementptr i8, i8* %7, i64 %10
%15 = getelementptr i8, i8* %0, i64 %10
%16 = icmp ugt i8* %15, %7
%17 = icmp ugt i8* %14, %0
%18 = and i1 %16, %17
br i1 %18, label %44, label %19
19: ; preds = %13
%20 = and i64 %10, 4294967264
%21 = and i64 %10, 31
%22 = getelementptr i8, i8* %7, i64 %20
br label %23
23: ; preds = %23, %19
%24 = phi i64 [ 0, %19 ], [ %40, %23 ]
%25 = sub i64 %10, %24
%26 = getelementptr i8, i8* %7, i64 %24
%27 = getelementptr inbounds i8, i8* %11, i64 %25
%28 = getelementptr inbounds i8, i8* %27, i64 -15
%29 = bitcast i8* %28 to <16 x i8>*
%30 = load <16 x i8>, <16 x i8>* %29
%31 = shufflevector <16 x i8> %30, <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>
%32 = getelementptr inbounds i8, i8* %27, i64 -16
%33 = getelementptr inbounds i8, i8* %32, i64 -15
%34 = bitcast i8* %33 to <16 x i8>*
%35 = load <16 x i8>, <16 x i8>* %34
%36 = shufflevector <16 x i8> %35, <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>
%37 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> %31, <16 x i8>* %37
%38 = getelementptr i8, i8* %26, i64 16
%39 = bitcast i8* %38 to <16 x i8>*
store <16 x i8> %36, <16 x i8>* %39
%40 = add nuw i64 %24, 32
%41 = icmp eq i64 %40, %20
br i1 %41, label %42, label %23
42: ; preds = %23
%43 = icmp eq i64 %20, %10
br i1 %43, label %55, label %44
44: ; preds = %13, %9, %42
%45 = phi i64 [ %10, %13 ], [ %10, %9 ], [ %21, %42 ]
%46 = phi i8* [ %7, %13 ], [ %7, %9 ], [ %22, %42 ]
br label %47
47: ; preds = %44, %47
%48 = phi i64 [ %52, %47 ], [ %45, %44 ]
%49 = phi i8* [ %53, %47 ], [ %46, %44 ]
%50 = getelementptr inbounds i8, i8* %11, i64 %48
%51 = load i8, i8* %50
store i8 %51, i8* %49
%52 = add nsw i64 %48, -1
%53 = getelementptr inbounds i8, i8* %49, i64 1
%54 = icmp ugt i64 %48, 1
br i1 %54, label %47, label %55
55: ; preds = %47, %42, %4
%56 = phi i8* [ %7, %4 ], [ %22, %42 ], [ %53, %47 ]
store i8 0, i8* %56
%57 = tail call i32 @memset(i8* %0, i32 0, i32 %2)
%58 = tail call i32 @strncpy(i8* %0, i8* %7, i32 %2)
%59 = tail call i32 @free(i8* %7)
br label %60
60: ; preds = %1, %55
ret void
}