#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 length(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *reverseIterate(char *string) {
  char newString[length(string)];
  int lengthVal = length(string);
  for (int i = lengthVal - 1; i >= 0; i--) {
    newString[lengthVal - i - 1] = string[i];
  }
  char *str;
  strncpy(str, newString, lengthVal);
  str[lengthVal] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<reverseIterate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <length@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <length@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11a5 <reverseIterate+0x85>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    116f <reverseIterate+0x4f>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseIterate>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <length@plt>
mov    %eax,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rbx,%rdi
call   1040 <length@plt>
test   %eax,%eax
jle    1295 <reverseIterate+0x175>
mov    %eax,%ecx
mov    %rcx,%rsi
cmp    $0x8,%eax
jb     1273 <reverseIterate+0x153>
cmp    $0x20,%eax
jae    116c <reverseIterate+0x4c>
xor    %edx,%edx
jmp    1214 <reverseIterate+0xf4>
mov    %ecx,%edx
and    $0xffffffe0,%edx
lea    (%rcx,%rbx,1),%rsi
add    $0xfffffffffffffff0,%rsi
xor    %edi,%edi
pxor   %xmm0,%xmm0
nop
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
movdqa %xmm2,(%r14,%rdi,1)
movdqa %xmm1,0x10(%r14,%rdi,1)
add    $0x20,%rdi
add    $0xffffffffffffffe0,%rsi
cmp    %rdi,%rdx
jne    1180 <reverseIterate+0x60>
cmp    %rcx,%rdx
je     1295 <reverseIterate+0x175>
test   $0x18,%cl
jne    1214 <reverseIterate+0xf4>
mov    %ecx,%esi
and    $0x1f,%esi
jmp    1273 <reverseIterate+0x153>
mov    %ecx,%r8d
and    $0xfffffff8,%r8d
mov    %ecx,%esi
and    $0x7,%esi
mov    %rcx,%rdi
sub    %rdx,%rdi
add    %rbx,%rdi
add    $0xfffffffffffffff8,%rdi
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   (%rdi),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%r14,%rdx,1)
add    $0x8,%rdx
add    $0xfffffffffffffff8,%rdi
cmp    %rdx,%r8
jne    1240 <reverseIterate+0x120>
cmp    %rcx,%r8
je     1295 <reverseIterate+0x175>
sub    %rsi,%rcx
add    $0x1,%rsi
add    %r14,%rcx
nopl   (%rax)
movzbl -0x2(%rbx,%rsi,1),%edx
mov    %dl,(%rcx)
add    $0xffffffffffffffff,%rsi
add    $0x1,%rcx
cmp    $0x1,%rsi
ja     1280 <reverseIterate+0x160>
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>

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

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