#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*/ gets(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int i = 0;
  char *str1 = malloc(180);
  char *str2 = malloc(sizeof(char) * 180);
  char *str3 = malloc(sizeof(char) * 180);
  puts("Enter first string");
  gets(str1);
  puts("Enter second string");
  gets(str2);
  printf("Before concatenation the string are: \n");
  puts(str1);
  puts(str2);
  while (*str1) {
    str3[i++] = *str1++;
  }
  while (*str2) {
    str3[i++] = *str2++;
  }
  str3[i] = '\0';
  printf("After concatenation the string are \n");
  puts(str3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0xb4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xb4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0xb4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gets@plt>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <gets@plt>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1200 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11c8 <main+0x88>
jmp    1205 <main+0xc5>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     123d <main+0xfd>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%dl
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1205 <main+0xc5>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xb4,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    $0xb4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0xb4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <gets@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <gets@plt>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r15),%cl
xor    %eax,%eax
test   %cl,%cl
je     11c2 <main+0x92>
nopl   0x0(%rax)
mov    %cl,(%r14,%rax,1)
movzbl 0x1(%r15,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    11b0 <main+0x80>
mov    (%rbx),%cl
test   %cl,%cl
je     11e3 <main+0xb3>
mov    %eax,%eax
add    $0x1,%rbx
xchg   %ax,%ax
mov    %cl,(%r14,%rax,1)
add    $0x1,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    11d0 <main+0xa0>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"Enter first string\00"
@.str.1 = [20 x i8] c"Enter second string\00"
@str = [38 x i8] c"Before concatenation the string are: \00"
@str.4 = [36 x i8] c"After concatenation the string are \00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(180) i8* @malloc(i32 180)
%2 = tail call dereferenceable_or_null(180) i8* @malloc(i32 180)
%3 = tail call dereferenceable_or_null(180) i8* @malloc(i32 180)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @gets(i8* %1)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @gets(i8* %2)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) %1)
%10 = tail call i32 @puts(i8* dereferenceable(1) %2)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %21
13: ; preds = %21
%14 = trunc i64 %26 to i32
br label %15
15: ; preds = %13, %0
%16 = phi i32 [ 0, %0 ], [ %14, %13 ]
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 0
br i1 %18, label %41, label %19
19: ; preds = %15
%20 = zext i32 %16 to i64
br label %30
21: ; preds = %0, %21
%22 = phi i64 [ %26, %21 ], [ 0, %0 ]
%23 = phi i8 [ %28, %21 ], [ %11, %0 ]
%24 = phi i8* [ %25, %21 ], [ %1, %0 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = add nuw i64 %22, 1
%27 = getelementptr inbounds i8, i8* %3, i64 %22
store i8 %23, i8* %27
%28 = load i8, i8* %25
%29 = icmp eq i8 %28, 0
br i1 %29, label %13, label %21
30: ; preds = %19, %30
%31 = phi i64 [ %20, %19 ], [ %35, %30 ]
%32 = phi i8 [ %17, %19 ], [ %37, %30 ]
%33 = phi i8* [ %2, %19 ], [ %34, %30 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = add nuw i64 %31, 1
%36 = getelementptr inbounds i8, i8* %3, i64 %31
store i8 %32, i8* %36
%37 = load i8, i8* %34
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %30
39: ; preds = %30
%40 = trunc i64 %35 to i32
br label %41
41: ; preds = %39, %15
%42 = phi i32 [ %16, %15 ], [ %40, %39 ]
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %3, i64 %43
store i8 0, i8* %44
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.4, i64 0, i64 0))
%46 = tail call i32 @puts(i8* dereferenceable(1) %3)
ret i32 0
}