#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*/ libcgi_error(int, char *, char *, int);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
unsigned int strlen(char const *);
char *strcat_ex(const char *str1, const char *str2) {
  char *new_str;
  unsigned int len;
  if (!str1 || !str2)
    return NULL;
  len = strlen(str1) + strlen(str2);
  new_str = (char *)malloc((len + 1) * sizeof(char *));
  if (!new_str)
    libcgi_error(4, "%s, line %s",
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/ingran/balzac/refs/heads/"
                 "master/package/libs/libcgi-1.0/src/string.c",
                 632);
  sprintf(new_str, "%s%s", str1, str2);
  new_str[len] = '\0';
  return new_str;
}


x86 assembly (clang, -O0):
<strcat_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <strcat_ex+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <strcat_ex+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11fc <strcat_ex+0xbc>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d1 <strcat_ex+0x91>
mov    $0x4,%edi
lea    0xe40(%rip),%rsi
lea    0xe45(%rip),%rdx
mov    $0x278,%ecx
call   1030 <libcgi_error@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xec7(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat_ex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     11bd <strcat_ex+0x7d>
mov    %rsi,%r14
test   %rsi,%rsi
je     11bd <strcat_ex+0x7d>
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
add    %ebx,%r12d
lea    0x8(,%r12,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a1 <strcat_ex+0x61>
lea    0xe75(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    $0x4,%edi
mov    $0x278,%ecx
call   1030 <libcgi_error@plt>
lea    0xf03(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    %r12d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s, line %s\00"
@.str.1 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ingran/balzac/refs/heads/master/package/libs/libcgi-1.0/src/string.c\00"
@.str.2 = [5 x i8] c"%s%s\00"
define i8* @strcat_ex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i8* null, i8** %3
br label %41
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = add i32 %16, %18
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = add i32 %20, 1
%22 = zext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %14
%30 = call i32 @libcgi_error(i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.1, i64 0, i64 0), i32 632)
br label %31
31: ; preds = %29, %14
%32 = load i8*, i8** %6
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34)
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %6
store i8* %40, i8** %3
br label %41
41: ; preds = %31, %13
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s, line %s\00"
@.str.1 = [159 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ingran/balzac/refs/heads/master/package/libs/libcgi-1.0/src/string.c\00"
@.str.2 = [5 x i8] c"%s%s\00"
define i8* @strcat_ex(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %8, %7
%10 = shl i32 %9, 3
%11 = add i32 %10, 8
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @libcgi_error(i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([159 x i8], [159 x i8]* @.str.1, i64 0, i64 0), i32 632)
br label %17
17: ; preds = %15, %6
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
%19 = zext i32 %9 to i64
%20 = getelementptr inbounds i8, i8* %13, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %2, %17
%22 = phi i8* [ %13, %17 ], [ null, %2 ]
ret i8* %22
}