#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*/ reverseStrOneRound(char *, int);
int strlen(char *);
char *reverseStr(char *s, int k) {
  char *head = s;
  while (strlen(head) >= 2 * k) {
    reverseStrOneRound(head, k);
    head += (2 * k);
  }
  reverseStrOneRound(head, k);
  return s;
}


x86 assembly (clang, -O0):
<reverseStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jl     1173 <reverseStr+0x53>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <reverseStrOneRound@plt>
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1137 <reverseStr+0x17>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <reverseStrOneRound@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseStr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    (%r15,%r15,1),%r12d
mov    %r14,%rbx
cmp    %r12d,%eax
jl     116b <reverseStr+0x4b>
movslq %r12d,%rbp
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <reverseStrOneRound@plt>
add    %rbp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r12d,%eax
jge    1150 <reverseStr+0x30>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <reverseStrOneRound@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @reverseStr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %13, %2
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = load i32, i32* %4
%11 = mul nsw i32 2, %10
%12 = icmp sge i32 %9, %11
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = load i8*, i8** %5
%15 = load i32, i32* %4
%16 = call i32 @reverseStrOneRound(i8* %14, i32 %15)
%17 = load i32, i32* %4
%18 = mul nsw i32 2, %17
%19 = load i8*, i8** %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %5
br label %7
22: ; preds = %7
%23 = load i8*, i8** %5
%24 = load i32, i32* %4
%25 = call i32 @reverseStrOneRound(i8* %23, i32 %24)
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @reverseStr(i8* returned %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = shl nsw i32 %1, 1
%5 = icmp slt i32 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = sext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i8* [ %0, %6 ], [ %11, %8 ]
%10 = tail call i32 @reverseStrOneRound(i8* %9, i32 %1)
%11 = getelementptr inbounds i8, i8* %9, i64 %7
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp slt i32 %12, %4
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = phi i8* [ %0, %2 ], [ %11, %8 ]
%16 = tail call i32 @reverseStrOneRound(i8* %15, i32 %1)
ret i8* %0
}