#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 */
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char a[32], b[32];
  int i, j, len = 0;
  printf("input: ");
  fgets(a, sizeof(a), stdin);
  for (i = 0; a[i] != '\n'; ++i)
    len++;
  printf("len: %d\n", len);
  for (i = len - 1, j = 0; j != len; --i, ++j)
    b[j] = a[i];
  b[j] = '\0';
  printf("output: %s\n", b);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x5c(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x54(%rbp)
movslq -0x54(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     1192 <main+0x72>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1169 <main+0x49>
mov    -0x5c(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x5c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x5c(%rbp),%eax
je     11e6 <main+0xc6>
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x58(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11b3 <main+0x93>
movslq -0x58(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x20,%esi
call   1040 <fgets@plt>
cmpb   $0xa,0x20(%rsp)
jne    1171 <main+0x51>
lea    0xea8(%rip),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12f6 <main+0x1d6>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,0x21(%rsp,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1180 <main+0x60>
lea    0xe76(%rip),%rdi
xor    %r15d,%r15d
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
je     12f6 <main+0x1d6>
mov    %ebx,%r8d
cmp    $0x8,%r8
jae    11b9 <main+0x99>
xor    %eax,%eax
mov    %r8,%rdx
jmp    12d5 <main+0x1b5>
cmp    $0x20,%r8d
jae    11c6 <main+0xa6>
xor    %eax,%eax
jmp    127b <main+0x15b>
mov    %ebx,%esi
mov    %ebx,%edx
and    $0x1f,%edx
mov    %r8,%rax
sub    %rdx,%rax
lea    (%rsp,%rsi,1),%rdi
add    $0x10,%rdi
sub    %rdx,%rsi
xor    %ecx,%ecx
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu -0x10(%rdi),%xmm1
movdqu (%rdi),%xmm2
movdqa %xmm2,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm2
pshufd $0x4e,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqa %xmm2,(%rsp,%rcx,1)
movdqa %xmm1,0x10(%rsp,%rcx,1)
add    $0x20,%rcx
add    $0xffffffffffffffe0,%rdi
cmp    %rcx,%rsi
jne    11f0 <main+0xd0>
test   %rdx,%rdx
je     12f3 <main+0x1d3>
cmp    $0x8,%edx
jb     12d5 <main+0x1b5>
mov    %ebx,%ecx
mov    %ebx,%edx
and    $0x7,%edx
sub    %rdx,%r8
mov    %rax,%rsi
neg    %rsi
add    %rsp,%rsi
add    $0x20,%rsi
add    %rcx,%rsi
add    $0xfffffffffffffff8,%rsi
sub    %rdx,%rcx
pxor   %xmm0,%xmm0
movq   (%rsi),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%rsp,%rax,1)
add    $0x8,%rax
add    $0xfffffffffffffff8,%rsi
cmp    %rax,%rcx
jne    12a0 <main+0x180>
mov    %r8,%rax
test   %rdx,%rdx
je     12f3 <main+0x1d3>
mov    %ebx,%esi
add    %r14,%rdx
add    $0xffffffffffffffff,%rdx
xchg   %ax,%ax
movzbl (%rdx),%ecx
mov    %cl,(%rsp,%rax,1)
add    $0x1,%rax
add    $0xffffffffffffffff,%rdx
cmp    %rax,%rsi
jne    12e0 <main+0x1c0>
mov    %ebx,%r15d
movb   $0x0,(%rsp,%r15,1)
lea    0xd0f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"input: \00"
@stdin = global i32 0
@.str.1 = [9 x i8] c"len: %d\0A\00"
@.str.2 = [12 x i8] c"output: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 32, i32 %13)
store i32 0, i32* %8
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
store i32 %24, i32* %10
br label %25
25: ; preds = %22
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %15
28: ; preds = %15
%29 = load i32, i32* %10
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %10
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %8
store i32 0, i32* %9
br label %33
33: ; preds = %45, %28
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %50
37: ; preds = %33
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %43
store i8 %41, i8* %44
br label %45
45: ; preds = %37
%46 = load i32, i32* %8
%47 = add nsw i32 %46, -1
store i32 %47, i32* %8
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %33
50: ; preds = %33
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %52
store i8 0, i8* %53
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"input: \00"
@stdin = global i32 0
@.str.1 = [9 x i8] c"len: %d\0A\00"
@.str.2 = [12 x i8] c"output: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %5, i32 32, i32 %8)
%10 = load i8, i8* %5
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %88
14: ; preds = %2, %14
%15 = phi i64 [ %16, %14 ], [ 0, %2 ]
%16 = add nuw nsw i64 %15, 1
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %14
20: ; preds = %14
%21 = trunc i64 %16 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %21, 0
br i1 %23, label %88, label %24
24: ; preds = %20
%25 = and i64 %16, 4294967295
%26 = icmp ult i64 %25, 8
br i1 %26, label %74, label %27
27: ; preds = %24
%28 = icmp ult i64 %25, 32
br i1 %28, label %55, label %29
29: ; preds = %27
%30 = and i64 %16, 31
%31 = sub nsw i64 %25, %30
br label %32
32: ; preds = %32, %29
%33 = phi i64 [ 0, %29 ], [ %49, %32 ]
%34 = xor i64 %33, -1
%35 = add i64 %25, %34
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 -15
%38 = bitcast i8* %37 to <16 x i8>*
%39 = load <16 x i8>, <16 x i8>* %38
%40 = shufflevector <16 x i8> %39, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%41 = getelementptr inbounds i8, i8* %36, i64 -31
%42 = bitcast i8* %41 to <16 x i8>*
%43 = load <16 x i8>, <16 x i8>* %42
%44 = shufflevector <16 x i8> %43, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %33
%46 = bitcast i8* %45 to <16 x i8>*
store <16 x i8> %40, <16 x i8>* %46
%47 = getelementptr inbounds i8, i8* %45, i64 16
%48 = bitcast i8* %47 to <16 x i8>*
store <16 x i8> %44, <16 x i8>* %48
%49 = add nuw i64 %33, 32
%50 = icmp eq i64 %49, %31
br i1 %50, label %51, label %32
51: ; preds = %32
%52 = icmp eq i64 %30, 0
br i1 %52, label %86, label %53
53: ; preds = %51
%54 = icmp ult i64 %30, 8
br i1 %54, label %74, label %55
55: ; preds = %27, %53
%56 = phi i64 [ %31, %53 ], [ 0, %27 ]
%57 = and i64 %16, 7
%58 = sub nsw i64 %25, %57
br label %59
59: ; preds = %59, %55
%60 = phi i64 [ %56, %55 ], [ %70, %59 ]
%61 = xor i64 %60, -1
%62 = add i64 %25, %61
%63 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %62
%64 = getelementptr inbounds i8, i8* %63, i64 -7
%65 = bitcast i8* %64 to <8 x i8>*
%66 = load <8 x i8>, <8 x i8>* %65
%67 = shufflevector <8 x i8> %66, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%68 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %60
%69 = bitcast i8* %68 to <8 x i8>*
store <8 x i8> %67, <8 x i8>* %69
%70 = add nuw i64 %60, 8
%71 = icmp eq i64 %70, %58
br i1 %71, label %72, label %59
72: ; preds = %59
%73 = icmp eq i64 %57, 0
br i1 %73, label %86, label %74
74: ; preds = %24, %53, %72
%75 = phi i64 [ 0, %24 ], [ %31, %53 ], [ %58, %72 ]
%76 = phi i64 [ %25, %24 ], [ %30, %53 ], [ %57, %72 ]
br label %77
77: ; preds = %74, %77
%78 = phi i64 [ %84, %77 ], [ %75, %74 ]
%79 = phi i64 [ %80, %77 ], [ %76, %74 ]
%80 = add nsw i64 %79, -1
%81 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %80
%82 = load i8, i8* %81
%83 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %78
store i8 %82, i8* %83
%84 = add nuw nsw i64 %78, 1
%85 = icmp eq i64 %84, %25
br i1 %85, label %86, label %77
86: ; preds = %77, %72, %51
%87 = and i64 %16, 4294967295
br label %88
88: ; preds = %86, %20, %12
%89 = phi i64 [ 0, %12 ], [ 0, %20 ], [ %87, %86 ]
%90 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %89
store i8 0, i8* %90
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret i32 0
}