#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 */
char *copy_header_value(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ safe_realloc(char *, int, char *, scalar_t__);
char *strcat(int /*<<< orphan*/, char *);
scalar_t__ strlen(char *);
void copy_or_concat_header_value(char **previous, char *text) {
  char *p = copy_header_value(text);
  if (*previous) {
    *previous = (strcat(
        safe_realloc(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/rfc822.c",
            381, *previous, (strlen(*previous) + strlen(", ") + 1)),
        ", "));
    *previous = (strcat(
        safe_realloc(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/rfc822.c",
            382, *previous, (strlen(*previous) + strlen(p) + 1)),
        p));
    free(p);
  } else
    *previous = p;
}


x86 assembly (clang, -O0):
<copy_or_concat_header_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <copy_header_value@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1241 <copy_or_concat_header_value+0xf1>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xee3(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdx
add    %rax,%rcx
add    $0x1,%rcx
lea    0xe48(%rip),%rdi
mov    $0x17d,%esi
call   1060 <safe_realloc@plt>
mov    %eax,%edi
lea    0xeb5(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
add    %rax,%rcx
add    $0x1,%rcx
lea    0xdec(%rip),%rdi
mov    $0x17e,%esi
call   1060 <safe_realloc@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    124c <copy_or_concat_header_value+0xfc>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_or_concat_header_value>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <copy_header_value@plt>
mov    %rax,%r14
mov    (%r15),%rbx
test   %rbx,%rbx
je     11f3 <copy_or_concat_header_value+0xa3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%rcx
lea    0xe7a(%rip),%r12
mov    %r12,%rdi
mov    $0x17d,%esi
mov    %rbx,%rdx
call   1060 <safe_realloc@plt>
lea    0xee3(%rip),%rsi
mov    %eax,%edi
call   1070 <strcat@plt>
mov    %rax,%rbx
mov    %rax,(%r15)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r13,1),%rcx
add    $0x1,%rcx
mov    %r12,%rdi
mov    $0x17e,%esi
mov    %rbx,%rdx
call   1060 <safe_realloc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rax,(%r15)
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    %r14,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [128 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/rfc822.c\00"
@.str.1 = [3 x i8] c", \00"
define void @copy_or_concat_header_value(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @copy_header_value(i8* %6)
store i8* %7, i8** %5
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %38
11: ; preds = %2
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
%16 = call i64 @strlen(i8* %15)
%17 = call i64 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = add nsw i64 %16, %17
%19 = add nsw i64 %18, 1
%20 = call i32 @safe_realloc(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str, i64 0, i64 0), i32 381, i8* %13, i64 %19)
%21 = call i8* @strcat(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8**, i8*** %3
store i8* %21, i8** %22
%23 = load i8**, i8*** %3
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %3
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %27, %29
%31 = add nsw i64 %30, 1
%32 = call i32 @safe_realloc(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str, i64 0, i64 0), i32 382, i8* %24, i64 %31)
%33 = load i8*, i8** %5
%34 = call i8* @strcat(i32 %32, i8* %33)
%35 = load i8**, i8*** %3
store i8* %34, i8** %35
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
br label %41
38: ; preds = %2
%39 = load i8*, i8** %5
%40 = load i8**, i8*** %3
store i8* %39, i8** %40
br label %41
41: ; preds = %38, %11
ret void
}

LLVM IR (-O2):
@.str = [128 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/rc0/mairix/refs/heads/master/rfc822.c\00"
@.str.1 = [3 x i8] c", \00"
define void @copy_or_concat_header_value(i8** nocapture %0, i8* %1) {
%3 = tail call i8* @copy_header_value(i8* %1)
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %4)
%8 = add nsw i64 %7, 3
%9 = tail call i32 @safe_realloc(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str, i64 0, i64 0), i32 381, i8* %4, i64 %8)
%10 = tail call i8* @strcat(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %0
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%13 = add i64 %11, 1
%14 = add i64 %13, %12
%15 = tail call i32 @safe_realloc(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @.str, i64 0, i64 0), i32 382, i8* %10, i64 %14)
%16 = tail call i8* @strcat(i32 %15, i8* %3)
store i8* %16, i8** %0
%17 = tail call i32 @free(i8* %3)
br label %19
18: ; preds = %2
store i8* %3, i8** %0
br label %19
19: ; preds = %18, %6
ret void
}