#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*/ printf(char *, ...);
unsigned long strlen(char *);
void _test_strRev(void) {
  char testStr[] = "1234567890A";
  unsigned long tmp, count;
  char tmpC;
  printf("\n");
  count = strlen(testStr);
  printf("Orig string: %s (size: %ld)\n", testStr, count);
  for (tmp = 0; (2 * tmp) < count; tmp++) {
    tmpC = testStr[tmp];
    testStr[tmp] = testStr[count - tmp - 1];
    testStr[count - tmp - 1] = tmpC;
  }
  printf("New String:  %s\n\n", testStr);
}


x86 assembly (clang, -O0):
<_test_strRev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    -0xc(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
cmp    -0x20(%rbp),%rax
jae    11ce <_test_strRev+0xae>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp,%rax,1),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    -0xc(%rbp,%rax,1),%cl
mov    -0x18(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <_test_strRev+0x55>
lea    -0xc(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_test_strRev>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0x3837363534333231,%rax
36 37 38
mov    %rax,(%rsp)
movl   $0x413039,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0xe9e(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15,%r15
je     1209 <_test_strRev+0xd9>
lea    -0x1(%r15),%rcx
mov    %rcx,%r8
shr    %r8
add    $0x1,%r8
cmp    $0x2,%rcx
jae    11a2 <_test_strRev+0x72>
xor    %ecx,%ecx
test   $0x1,%r8b
jne    11f2 <_test_strRev+0xc2>
jmp    1209 <_test_strRev+0xd9>
lea    0x1(%rsp),%rdx
lea    (%rsp,%rcx,1),%rsi
mov    %r8,%rdi
and    $0xfffffffffffffffe,%rdi
neg    %rdi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%rdx),%ebx
movzbl (%rsi,%rcx,1),%eax
mov    %al,-0x1(%rdx)
mov    %bl,(%rsi,%rcx,1)
movzbl (%rdx),%eax
movzbl -0x1(%rsi,%rcx,1),%ebx
mov    %bl,(%rdx)
mov    %al,-0x1(%rsi,%rcx,1)
add    $0x2,%rdx
add    $0xfffffffffffffffe,%rcx
cmp    %rcx,%rdi
jne    11c0 <_test_strRev+0x90>
neg    %rcx
test   $0x1,%r8b
je     1209 <_test_strRev+0xd9>
mov    (%rsp,%rcx,1),%al
mov    %rcx,%rdx
not    %rdx
add    %rdx,%r15
mov    (%rsp,%r15,1),%dl
mov    %dl,(%rsp,%rcx,1)
mov    %al,(%rsp,%r15,1)
lea    0xe19(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const._test_strRev.testStr = [12 x i8] c"1234567890A\00"
@.str = [2 x i8] c"\0A\00"
@.str.1 = [29 x i8] c"Orig string: %s (size: %ld)\0A\00"
@.str.2 = [18 x i8] c"New String: %s\0A\0A\00"
define void @_test_strRev() {
%1 = alloca [12 x i8]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8
%5 = bitcast [12 x i8]* %1 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %3
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%10 = load i64, i64* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %9, i64 %10)
store i64 0, i64* %2
br label %12
12: ; preds = %35, %0
%13 = load i64, i64* %2
%14 = mul i64 2, %13
%15 = load i64, i64* %3
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %38
17: ; preds = %12
%18 = load i64, i64* %2
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %4
%21 = load i64, i64* %3
%22 = load i64, i64* %2
%23 = sub i64 %21, %22
%24 = sub i64 %23, 1
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i64, i64* %2
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %27
store i8 %26, i8* %28
%29 = load i8, i8* %4
%30 = load i64, i64* %3
%31 = load i64, i64* %2
%32 = sub i64 %30, %31
%33 = sub i64 %32, 1
%34 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %33
store i8 %29, i8* %34
br label %35
35: ; preds = %17
%36 = load i64, i64* %2
%37 = add i64 %36, 1
store i64 %37, i64* %2
br label %12
38: ; preds = %12
%39 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %39)
ret void
}

LLVM IR (-O2):
@__const._test_strRev.testStr = [12 x i8] c"1234567890A\00"
@.str.1 = [29 x i8] c"Orig string: %s (size: %ld)\0A\00"
@.str.2 = [18 x i8] c"New String: %s\0A\0A\00"
define void @_test_strRev() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @putchar(i32 10)
%4 = call i64 @strlen(i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %2, i64 %4)
%6 = icmp eq i64 %4, 0
br i1 %6, label %44, label %7
7: ; preds = %0
%8 = add i64 %4, -1
%9 = lshr i64 %8, 1
%10 = add nuw i64 %9, 1
%11 = and i64 %10, 1
%12 = icmp ult i64 %8, 2
br i1 %12, label %34, label %13
13: ; preds = %7
%14 = and i64 %10, -2
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %31, %15 ]
%17 = phi i64 [ 0, %13 ], [ %32, %15 ]
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %16
%19 = load i8, i8* %18
%20 = xor i64 %16, -1
%21 = add i64 %4, %20
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
store i8 %23, i8* %18
store i8 %19, i8* %22
%24 = or i64 %16, 1
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sub nuw nsw i64 -2, %16
%28 = add i64 %4, %27
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %25
store i8 %26, i8* %29
%31 = add nuw nsw i64 %16, 2
%32 = add i64 %17, 2
%33 = icmp eq i64 %32, %14
br i1 %33, label %34, label %15
34: ; preds = %15, %7
%35 = phi i64 [ 0, %7 ], [ %31, %15 ]
%36 = icmp eq i64 %11, 0
br i1 %36, label %44, label %37
37: ; preds = %34
%38 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %35
%39 = load i8, i8* %38
%40 = xor i64 %35, -1
%41 = add i64 %4, %40
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %41
%43 = load i8, i8* %42
store i8 %43, i8* %38
store i8 %39, i8* %42
br label %44
44: ; preds = %37, %34, %0
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret void
}