#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int,
                           char *);
int getpid();
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *merge(char *s1, char *s2) {
  char *temp;
  if (s1 == NULL) {
    temp = strdup(s2);
    if (temp == NULL) {
      fprintf(stderr,
              "kickstart[%d]: %s[%d]: "
              "strdup: %s\n",
              getpid(),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/"
              "src/tools/pegasus-kickstart/invoke.c",
              69, strerror(errno));
      return NULL;
    }
    return temp;
  } else {
    size_t len = strlen(s1) + strlen(s2) + 2;
    temp = (char *)malloc(len);
    if (temp == NULL) {
      fprintf(stderr,
              "kickstart[%d]: %s[%d]: "
              "malloc: %s\n",
              getpid(),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/"
              "src/tools/pegasus-kickstart/invoke.c",
              77, strerror(errno));
      return NULL;
    }
    strncpy(temp, s1, len);
    strncat(temp, s2, len);
    return temp;
  }
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1213 <merge+0x93>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1206 <merge+0x86>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%r9
lea    0xe19(%rip),%rsi
lea    0xe35(%rip),%rcx
mov    $0x45,%r8d
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cd <merge+0x14d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12cd <merge+0x14d>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a3 <merge+0x123>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %rax,%r9
lea    0xe44(%rip),%rsi
lea    0xd98(%rip),%rcx
mov    $0x4d,%r8d
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cd <merge+0x14d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <strncat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11db <merge+0x5b>
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
add    $0x2,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     122c <merge+0xac>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <strncat@plt>
jmp    126f <merge+0xef>
mov    %r14,%rdi
call   1090 <strdup@plt>
mov    %rax,%r15
test   %rax,%rax
jne    126f <merge+0xef>
mov    0x2dea(%rip),%rax
mov    (%rax),%ebx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xde7(%rip),%rsi
lea    0xe03(%rip),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
mov    $0x45,%r8d
jmp    1267 <merge+0xe7>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe72(%rip),%rsi
lea    0xdc6(%rip),%rcx
mov    %ebx,%edi
mov    %ebp,%edx
mov    $0x4d,%r8d
mov    %rax,%r9
call   1070 <fprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"kickstart[%d]: %s[%d]: strdup: %s\0A\00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/invoke.c\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"kickstart[%d]: %s[%d]: malloc: %s\0A\00"
define i8* @merge(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %23
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (...) @getpid()
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %17, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 69, i8* %19)
store i8* null, i8** %3
br label %52
21: ; preds = %10
%22 = load i8*, i8** %6
store i8* %22, i8** %3
br label %52
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %25, %27
%29 = add nsw i32 %28, 2
%30 = sext i32 %29 to i64
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %42
36: ; preds = %23
%37 = load i32, i32* @stderr
%38 = call i32 (...) @getpid()
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %38, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 77, i8* %40)
store i8* null, i8** %3
br label %52
42: ; preds = %23
%43 = load i8*, i8** %6
%44 = load i8*, i8** %4
%45 = load i64, i64* %7
%46 = call i32 @strncpy(i8* %43, i8* %44, i64 %45)
%47 = load i8*, i8** %6
%48 = load i8*, i8** %5
%49 = load i64, i64* %7
%50 = call i32 @strncat(i8* %47, i8* %48, i64 %49)
%51 = load i8*, i8** %6
store i8* %51, i8** %3
br label %52
52: ; preds = %42, %36, %21, %15
%53 = load i8*, i8** %3
ret i8* %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"kickstart[%d]: %s[%d]: strdup: %s\0A\00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/invoke.c\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"kickstart[%d]: %s[%d]: malloc: %s\0A\00"
define i8* @merge(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = tail call i8* @strdup(i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %31
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (...) @getpid()
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 69, i8* %11)
br label %31
13: ; preds = %2
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strlen(i8* %1)
%16 = add i32 %14, 2
%17 = add i32 %16, %15
%18 = sext i32 %17 to i64
%19 = tail call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %28
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = tail call i32 (...) @getpid()
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 77, i8* %26)
br label %31
28: ; preds = %13
%29 = tail call i32 @strncpy(i8* %20, i8* %0, i64 %18)
%30 = tail call i32 @strncat(i8* %20, i8* %1, i64 %18)
br label %31
31: ; preds = %22, %28, %4, %7
%32 = phi i8* [ null, %7 ], [ %5, %4 ], [ null, %22 ], [ %20, %28 ]
ret i8* %32
}