#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *Concat2Strings(char *str1, char *str2) {
  if (((str1 == NULL) || (str1[0] == '\0')) ||
      ((str2 == NULL) || (str2[0] == '\0'))) {
    printf("ERROR IN CONCAT 2 STRING");
    return NULL;
  }
  char *str3 = (char *)malloc(1 + strlen(str1) + strlen(str2));
  strcpy(str3, str1);
  strcat(str3, str2);
  return str3;
}


x86 assembly (clang, -O0):
<Concat2Strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <Concat2Strings+0x46>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <Concat2Strings+0x46>
cmpq   $0x0,-0x18(%rbp)
je     1196 <Concat2Strings+0x46>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11af <Concat2Strings+0x5f>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fb <Concat2Strings+0xab>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Concat2Strings>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11ab <Concat2Strings+0x5b>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ab <Concat2Strings+0x5b>
mov    %rdi,%r15
cmpb   $0x0,(%rdi)
je     11ab <Concat2Strings+0x5b>
cmpb   $0x0,(%r14)
je     11ab <Concat2Strings+0x5b>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11b9 <Concat2Strings+0x69>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ERROR IN CONCAT 2 STRING\00"
define i8* @Concat2Strings(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %24, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %9
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18, %15, %9, %2
%25 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %42
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 1, %28
%30 = load i8*, i8** %5
%31 = call i64 @strlen(i8* %30)
%32 = add nsw i64 %29, %31
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = load i8*, i8** %4
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %6
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = load i8*, i8** %6
store i8* %41, i8** %3
br label %42
42: ; preds = %26, %24
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [25 x i8] c"ERROR IN CONCAT 2 STRING\00"
define i8* @Concat2Strings(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
%7 = icmp eq i8* %1, null
%8 = or i1 %7, %6
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9, %4, %2
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %23
14: ; preds = %9
%15 = tail call i64 @strlen(i8* %0)
%16 = add nsw i64 %15, 1
%17 = tail call i64 @strlen(i8* %1)
%18 = add nsw i64 %16, %17
%19 = tail call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @strcpy(i8* %20, i8* %0)
%22 = tail call i32 @strcat(i8* %20, i8* %1)
br label %23
23: ; preds = %14, %12
%24 = phi i8* [ null, %12 ], [ %20, %14 ]
ret i8* %24
}