#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*/ b;

/* Variables and functions */
scalar_t__ gets(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *);
char *revstring(char *);
int /*<<< orphan*/ stradd(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int main() {
  char a[1010], b[1010], c[1010];
  int to = 0, len, len1, len2, len3;
  memset(b, '\0', sizeof(b));
  while (gets(a)) {
    stradd(a, b);
    if (to == 0) {
      printf("%s\n", revstring(a));
    }
    strcpy(b, stradd(a, b));
    printf("%s\n", b);
    to++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc04(%rbp)
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
mov    $0x3f2,%edx
call   1060 <memset@plt>
lea    -0x400(%rbp),%rdi
call   1080 <gets@plt>
cmp    $0x0,%rax
je     1236 <main+0xd6>
lea    -0x400(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   1070 <stradd@plt>
cmpl   $0x0,-0xc04(%rbp)
jne    11e0 <main+0x80>
lea    -0x400(%rbp),%rdi
call   1040 <revstring@plt>
mov    %rax,%rsi
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
lea    -0x800(%rbp),%rax
mov    %rax,-0xc20(%rbp)
lea    -0x400(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   1070 <stradd@plt>
mov    -0xc20(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x800(%rbp),%rsi
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc04(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc04(%rbp)
jmp    118f <main+0x2f>
xor    %eax,%eax
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x3f2,%edx
call   1060 <memset@plt>
lea    0x400(%rsp),%rdi
call   1080 <gets@plt>
test   %rax,%rax
je     1238 <main+0xd8>
lea    0x400(%rsp),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stradd@plt>
mov    %r14,%rdi
call   1040 <revstring@plt>
lea    0xe4a(%rip),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stradd@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1080 <gets@plt>
test   %rax,%rax
je     1238 <main+0xd8>
lea    0x400(%rsp),%r14
mov    %rsp,%rbx
lea    0xe00(%rip),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stradd@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <stradd@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1080 <gets@plt>
test   %rax,%rax
jne    1200 <main+0xa0>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1010 x i8]
%3 = alloca [1010 x i8]
%4 = alloca [1010 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%10 = getelementptr inbounds [1010 x i8], [1010 x i8]* %3, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i8 signext 0, i32 1010)
br label %12
12: ; preds = %26, %0
%13 = getelementptr inbounds [1010 x i8], [1010 x i8]* %2, i64 0, i64 0
%14 = call i64 @gets(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = getelementptr inbounds [1010 x i8], [1010 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [1010 x i8], [1010 x i8]* %3, i64 0, i64 0
%19 = call i32 @stradd(i8* %17, i8* %18)
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = getelementptr inbounds [1010 x i8], [1010 x i8]* %2, i64 0, i64 0
%24 = call i8* @revstring(i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %16
%27 = getelementptr inbounds [1010 x i8], [1010 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [1010 x i8], [1010 x i8]* %2, i64 0, i64 0
%29 = getelementptr inbounds [1010 x i8], [1010 x i8]* %3, i64 0, i64 0
%30 = call i32 @stradd(i8* %28, i8* %29)
%31 = call i32 @strcpy(i8* %27, i32 %30)
%32 = getelementptr inbounds [1010 x i8], [1010 x i8]* %3, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %12
36: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [1010 x i8]
%2 = alloca [1010 x i8]
%3 = getelementptr inbounds [1010 x i8], [1010 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1010 x i8], [1010 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 1010)
%6 = call i64 @gets(i8* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %0
%9 = call i32 @stradd(i8* %3, i8* %4)
%10 = call i8* @revstring(i8* %3)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @stradd(i8* %3, i8* %4)
%13 = call i32 @strcpy(i8* %4, i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%15 = call i64 @gets(i8* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %8, %17
%18 = call i32 @stradd(i8* %3, i8* %4)
%19 = call i32 @stradd(i8* %3, i8* %4)
%20 = call i32 @strcpy(i8* %4, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%22 = call i64 @gets(i8* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %17
24: ; preds = %17, %8, %0
ret i32 0
}