#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 *, ...);
int /*<<< orphan*/ scanf(char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, const char *argv[]) {
  char name1[256], name2[256], name3[256], result[256];
  printf("===== Exercise 14 =====\n");
  printf("Concatenate & Return Backwards!\n");
  printf("Enter 3 names in one line. (Ex. AAA BBB CCC): \n");
  scanf("%s %s %s", name1, name2, name3);
  strcat(name2, name3);
  strcat(name1, name2);
  int length = 0;
  for (int i = 0; name1[i] != '\0'; i++) {
    length++;
  }
  for (int j = 0, k = length - 1; j < length; j++, k--) {
    result[j] = name1[k];
  }
  printf("--> Concatenated word: %s\n", name1);
  printf("--> Backwards word: %s\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    -0x210(%rbp),%rdx
lea    -0x310(%rbp),%rcx
lea    0xedb(%rip),%rdi
call   1040 <scanf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x310(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x418(%rbp)
movslq -0x418(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1209 <main+0xd9>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    11ce <main+0x9e>
movl   $0x0,-0x41c(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x420(%rbp)
mov    -0x41c(%rbp),%eax
cmp    -0x414(%rbp),%eax
jge    1273 <main+0x143>
movslq -0x420(%rbp),%rax
mov    -0x110(%rbp,%rax,1),%cl
movslq -0x41c(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x420(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x420(%rbp)
jmp    1222 <main+0xf2>
lea    -0x110(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rdi
mov    %rsp,%r14
lea    0x300(%rsp),%rbx
lea    0x200(%rsp),%r15
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1050 <scanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
cmpb   $0x0,(%rsp)
je     1347 <main+0x207>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    11c0 <main+0x80>
test   %eax,%eax
je     1347 <main+0x207>
mov    %eax,%r8d
cmp    $0x8,%r8
jae    11e6 <main+0xa6>
xor    %ecx,%ecx
mov    %r8,%rsi
jmp    1319 <main+0x1d9>
cmp    $0x20,%r8d
jae    11f3 <main+0xb3>
xor    %ecx,%ecx
jmp    12b6 <main+0x176>
mov    %eax,%edi
mov    %eax,%esi
and    $0x1f,%esi
mov    %r8,%rcx
sub    %rsi,%rcx
lea    (%rsp,%rdi,1),%rbx
add    $0xfffffffffffffff0,%rbx
sub    %rsi,%rdi
xor    %edx,%edx
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqu -0x10(%rbx),%xmm1
movdqu (%rbx),%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,0x100(%rsp,%rdx,1)
movdqa %xmm1,0x110(%rsp,%rdx,1)
add    $0x20,%rdx
add    $0xffffffffffffffe0,%rbx
cmp    %rdx,%rdi
jne    1220 <main+0xe0>
test   %rsi,%rsi
je     1347 <main+0x207>
cmp    $0x8,%esi
jb     1319 <main+0x1d9>
mov    %eax,%edx
mov    %eax,%esi
and    $0x7,%esi
sub    %rsi,%r8
mov    %rcx,%rdi
neg    %rdi
add    %rsp,%rdi
add    %rdx,%rdi
add    $0xfffffffffffffff8,%rdi
sub    %rsi,%rdx
pxor   %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movq   (%rdi),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,0x100(%rsp,%rcx,1)
add    $0x8,%rcx
add    $0xfffffffffffffff8,%rdi
cmp    %rcx,%rdx
jne    12e0 <main+0x1a0>
mov    %r8,%rcx
test   %rsi,%rsi
je     1347 <main+0x207>
mov    %eax,%eax
lea    (%rsi,%r14,1),%rdx
add    $0xffffffffffffffff,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rdx),%ebx
mov    %bl,0x100(%rsp,%rcx,1)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rdx
cmp    %rcx,%rax
jne    1330 <main+0x1f0>
lea    0xcbb(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xcc5(%rip),%rdi
lea    0x100(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"===== Exercise 14 =====\0A\00"
@.str.1 = [33 x i8] c"Concatenate & Return Backwards!\0A\00"
@.str.2 = [48 x i8] c"Enter 3 names in one line. (Ex. AAA BBB CCC): \0A\00"
@.str.3 = [9 x i8] c"%s %s %s\00"
@.str.4 = [27 x i8] c"--> Concatenated word: %s\0A\00"
@.str.5 = [24 x i8] c"--> Backwards word: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%20 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %17, i8* %18, i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @strcat(i8* %24, i8* %25)
store i32 0, i32* %10
store i32 0, i32* %11
br label %27
27: ; preds = %37, %2
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %37
37: ; preds = %34
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %27
40: ; preds = %27
store i32 0, i32* %12
%41 = load i32, i32* %10
%42 = sub nsw i32 %41, 1
store i32 %42, i32* %13
br label %43
43: ; preds = %55, %40
%44 = load i32, i32* %12
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %60
47: ; preds = %43
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %53
store i8 %51, i8* %54
br label %55
55: ; preds = %47
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 1
store i32 %57, i32* %12
%58 = load i32, i32* %13
%59 = add nsw i32 %58, -1
store i32 %59, i32* %13
br label %43
60: ; preds = %43
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %63)
ret i32 0
}

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