#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*/ strcat(char *, char *);
size_t strlen(char *);
const char *invStr(char *in) {
  static char b[128];
  b[0] = '\0';
  int z;
  for (z = strlen(in) - 1; z >= 0; z--) {
    char c[2];
    c[0] = in[z];
    c[1] = '\0';
    strcat(b, c);
  }
  b[strlen(in)] = '\0';
  return b;
}


x86 assembly (clang, -O0):
<invStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2f0d(%rip)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%rax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     117d <invStr+0x5d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xe(%rbp)
movb   $0x0,-0xd(%rbp)
lea    -0xe(%rbp),%rsi
lea    0x2ed6(%rip),%rdi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <invStr+0x23>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
lea    0x2eb0(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ea5(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invStr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movb   $0x0,0x2f09(%rip)
call   1030 <strlen@plt>
mov    %rax,%r13
add    $0xffffffff,%eax
js     1184 <invStr+0x64>
mov    %eax,%ebx
add    %r14,%rbx
lea    0x2ef0(%rip),%r15
lea    0xe(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%eax
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <strcat@plt>
add    $0xffffffff,%r13d
add    $0xffffffffffffffff,%rbx
test   %r13d,%r13d
jg     1160 <invStr+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x2ead(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@invStr.b = internal global [128 x i8] zeroinitializer
define i8* @invStr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i8]
store i8* %0, i8** %2
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0)
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = sub i64 %6, 1
%8 = trunc i64 %7 to i32
store i32 %8, i32* %3
br label %9
9: ; preds = %22, %1
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %17, i8* %18
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %19
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %12
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
store i32 %24, i32* %3
br label %9
25: ; preds = %9
%26 = load i8*, i8** %2
%27 = call i64 @strlen(i8* %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* @invStr.b, i64 0, i64 %27
store i8 0, i8* %28
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0)
}

LLVM IR (-O2):
@invStr.b = internal global [128 x i8] zeroinitializer
define i8* @invStr(i8* nocapture %0) {
%2 = alloca [2 x i8]
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = add i32 %4, -1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ %5, %7 ], [ %16, %10 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %8
store i8 0, i8* %9
%15 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0), i8* %8)
%16 = add nsw i32 %11, -1
%17 = icmp sgt i32 %11, 0
br i1 %17, label %10, label %18
18: ; preds = %10, %1
%19 = call i64 @strlen(i8* dereferenceable(1) %0)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* @invStr.b, i64 0, i64 %19
store i8 0, i8* %20
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @invStr.b, i64 0, i64 0)
}