#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 *, char *);
char *reverse(char *, int, int *);
int main(int argc, char const *argv[]) {
  int idx = 0;
  printf("%s\n", reverse("w", 1, &idx));
  idx = 0;
  printf("%s\n", reverse("xbwwb", 5, &idx));
  idx = 0;
  printf("%s\n", reverse("xbwxwbbwb", 9, &idx));
  idx = 0;
  printf("%s\n", reverse("xxwwwbxwxwbbbwwxxxwwbbbwwwwbb", 29, &idx));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x1,%esi
lea    -0x14(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,%rsi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x5,%esi
lea    -0x14(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe72(%rip),%rdi
mov    $0x9,%esi
lea    -0x14(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,%rsi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe51(%rip),%rdi
mov    $0x1d,%esi
lea    -0x14(%rbp),%rdx
call   1030 <reverse@plt>
mov    %rax,%rsi
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%r14
mov    $0x1,%esi
mov    %r14,%rdx
call   1030 <reverse@plt>
lea    0xeb4(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
lea    0xea0(%rip),%rdi
mov    $0x5,%esi
mov    %r14,%rdx
call   1030 <reverse@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
lea    0xe7f(%rip),%rdi
mov    $0x9,%esi
mov    %r14,%rdx
call   1030 <reverse@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
lea    0xe62(%rip),%rdi
mov    $0x1d,%esi
mov    %r14,%rdx
call   1030 <reverse@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"xbwwb\00"
@.str.3 = [10 x i8] c"xbwxwbbwb\00"
@.str.4 = [30 x i8] c"xxwwwbxwxwbbbwwxxxwwbbbwwwwbb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = call i8* @reverse(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 0, i32* %6
%9 = call i8* @reverse(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5, i32* %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 0, i32* %6
%11 = call i8* @reverse(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9, i32* %6)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %6
%13 = call i8* @reverse(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 29, i32* %6)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"xbwwb\00"
@.str.3 = [10 x i8] c"xbwxwbbwb\00"
@.str.4 = [30 x i8] c"xxwwwbxwxwbbbwwxxxwwbbbwwwwbb\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i8* @reverse(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1, i32* %3)
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
store i32 0, i32* %3
%7 = call i8* @reverse(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5, i32* %3)
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
store i32 0, i32* %3
%9 = call i8* @reverse(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9, i32* %3)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 0, i32* %3
%11 = call i8* @reverse(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 29, i32* %3)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
ret i32 0
}