#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*/ puts(char *);
void concat(char str1[100], char str2[100], int length) {
  int j;
  for (j = 0; str2[j] != '\0'; ++j, ++length) {
    str1[length] = str2[j];
  }
  str1[length] = '\0';
  printf("\nConcatenated String: ");
  puts(str1);
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     117c <concat+0x5c>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <concat+0x1a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %rbx
mov    %rdi,%rbx
mov    (%rsi),%al
test   %al,%al
je     1152 <concat+0x32>
movslq %edx,%rdi
add    %rbx,%rdi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rdi,%rcx,1)
movzbl 0x1(%rsi,%rcx,1),%eax
add    $0x1,%rcx
test   %al,%al
jne    1140 <concat+0x20>
add    %ecx,%edx
movslq %edx,%rax
movb   $0x0,(%rbx,%rax,1)
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <puts@plt>

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

LLVM IR (-O2):
@.str = [23 x i8] c"\0AConcatenated String: \00"
define void @concat(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = sext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %14, %8 ]
%10 = phi i64 [ 0, %6 ], [ %13, %8 ]
%11 = phi i8 [ %4, %6 ], [ %16, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %11, i8* %12
%13 = add nuw nsw i64 %10, 1
%14 = add i64 %9, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %13
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %8
%19 = trunc i64 %14 to i32
br label %20
20: ; preds = %18, %3
%21 = phi i32 [ %2, %3 ], [ %19, %18 ]
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) %0)
ret void
}