#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 */
size_t strlen(char *);
void flip_word(char *input, char *output) {
  if (strlen(input) > 1) {
    flip_word(++input, output);
  }
  output[strlen(input) - 1] = input[0];
  output[strlen(input)] = '\0';
}


x86 assembly (clang, -O0):
<flip_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%rax
jbe    1158 <flip_word+0x38>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <flip_word@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x21(%rbp),%dl
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_word>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     1144 <flip_word+0x24>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <flip_word@plt>
mov    (%rbx),%bpl
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %bpl,-0x1(%rax,%r14,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @flip_word(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp ugt i64 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
tail call void @flip_word(i8* %6, i8* %1)
br label %7
7: ; preds = %5, %2
%8 = phi i8* [ %6, %5 ], [ %0, %2 ]
%9 = load i8, i8* %8
%10 = tail call i64 @strlen(i8* %8)
%11 = add i64 %10, -1
%12 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 %9, i8* %12
%13 = tail call i64 @strlen(i8* %8)
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 0, i8* %14
ret void
}