#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 *);
int main() {
  int i, j, k, n;
  char str1[50], str2[50], str3[50];
  printf("Enter the two strings to concatenate\n");
  scanf("%s %s", str1, str2);
  while (i < 50 && str1[i] != '\0') {
    i += 1;
  }
  n = i;
  for (j = 0; j < n; j++) {
    str3[j] = str1[j];
  }
  for (i = 0, k = n; k < 50; i++, k++) {
    str3[k] = str2[i];
  }
  printf("The concatenated string is \n");
  printf("%s", str3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    -0x90(%rbp),%rdx
lea    0xed4(%rip),%rdi
call   1040 <scanf@plt>
xor    %eax,%eax
cmpl   $0x32,-0x8(%rbp)
mov    %al,-0xd1(%rbp)
jge    117e <main+0x5e>
movslq -0x8(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xd1(%rbp)
mov    -0xd1(%rbp),%al
test   $0x1,%al
jne    1191 <main+0x71>
jmp    119f <main+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x37>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <main+0xb9>
movslq -0xc(%rbp),%rax
mov    -0x50(%rbp,%rax,1),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0xd0(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <main+0x8c>
movl   $0x0,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x32,-0x10(%rbp)
jge    121d <main+0xfd>
movslq -0x8(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0xd0(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e6 <main+0xc6>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xb8,%rsp
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x80(%rsp),%rsi
lea    0x40(%rsp),%rdx
call   1050 <scanf@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Enter the two strings to concatenate\0A\00"
@.str.1 = [6 x i8] c"%s %s\00"
@.str.2 = [29 x i8] c"The concatenated string is \0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [50 x i8]
%7 = alloca [50 x i8]
%8 = alloca [50 x i8]
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %11)
br label %13
13: ; preds = %25, %0
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 50
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br label %23
23: ; preds = %16, %13
%24 = phi i1 [ false, %13 ], [ %22, %16 ]
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %13
28: ; preds = %23
%29 = load i32, i32* %2
store i32 %29, i32* %5
store i32 0, i32* %3
br label %30
30: ; preds = %42, %28
%31 = load i32, i32* %3
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %40
store i8 %38, i8* %41
br label %42
42: ; preds = %34
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %30
45: ; preds = %30
store i32 0, i32* %2
%46 = load i32, i32* %5
store i32 %46, i32* %4
br label %47
47: ; preds = %58, %45
%48 = load i32, i32* %4
%49 = icmp slt i32 %48, 50
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load i32, i32* %2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %50
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %47
63: ; preds = %47
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%65 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %65)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%s %s\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [37 x i8] c"Enter the two strings to concatenate\00"
@str.4 = [28 x i8] c"The concatenated string is \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %5)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.4, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
ret i32 0
}