#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 *calloc(int, int);
long strlen(char const *);
char *coerceReverseString(const char *s) {
  long len = strlen(s);
  char *t = calloc(1 + len, 1);
  for (int i = 0; i < len; i++)
    t[len - i - 1] = s[i];
  return t;
}


x86 assembly (clang, -O0):
<coerceReverseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1195 <coerceReverseString+0x75>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rsi
sub    %rsi,%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <coerceReverseString+0x38>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coerceReverseString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rbx,%rbx
jle    1282 <coerceReverseString+0x162>
cmp    $0x8,%rbx
jae    1153 <coerceReverseString+0x33>
xor    %r8d,%r8d
jmp    1262 <coerceReverseString+0x142>
cmp    $0x20,%rbx
jae    1161 <coerceReverseString+0x41>
xor    %r8d,%r8d
jmp    120b <coerceReverseString+0xeb>
mov    %rbx,%r8
and    $0xffffffffffffffe0,%r8
lea    0x10(%r14),%rdx
lea    (%rbx,%rax,1),%rsi
add    $0xfffffffffffffff0,%rsi
mov    %r8,%rdi
neg    %rdi
xor    %ecx,%ecx
pxor   %xmm0,%xmm0
movdqu -0x10(%rdx),%xmm1
movdqu (%rdx),%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 %xmm1,(%rsi,%rcx,1)
movdqa %xmm2,%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
punpckhbw %xmm0,%xmm2
pshufd $0x4e,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm1,%xmm2
movdqu %xmm2,-0x10(%rsi,%rcx,1)
add    $0x20,%rdx
add    $0xffffffffffffffe0,%rcx
cmp    %rcx,%rdi
jne    1180 <coerceReverseString+0x60>
cmp    %r8,%rbx
je     1282 <coerceReverseString+0x162>
test   $0x18,%bl
je     1262 <coerceReverseString+0x142>
mov    %r8,%rcx
mov    %rbx,%r8
and    $0xfffffffffffffff8,%r8
lea    (%r14,%rcx,1),%rdx
lea    (%rbx,%rax,1),%rsi
add    $0xfffffffffffffff8,%rsi
neg    %rcx
mov    %r8,%rdi
neg    %rdi
pxor   %xmm0,%xmm0
xchg   %ax,%ax
movq   (%rdx),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%rsi,%rcx,1)
add    $0x8,%rdx
add    $0xfffffffffffffff8,%rcx
cmp    %rcx,%rdi
jne    1230 <coerceReverseString+0x110>
cmp    %r8,%rbx
je     1282 <coerceReverseString+0x162>
sub    %r8,%rbx
add    %r8,%r14
nopl   0x0(%rax,%rax,1)
movzbl (%r14),%ecx
mov    %cl,-0x1(%rax,%rbx,1)
add    $0x1,%r14
add    $0xffffffffffffffff,%rbx
jne    1270 <coerceReverseString+0x150>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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