#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 */
typedef size_t uint32_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_sysmap_str(char);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int /*<<< orphan*/ runtime_exception(char *, char *, int);
char *strchr(char *, char);
char *strdup(char *);
scalar_t__ strlen(char *);
char *expand_command(char *original_rawcmd) {
  char *ret, *tofree, *last_p, *p;
  char buffer[256] = {' '};
  uint32_t j = 0;
  if (((tofree) = strdup(original_rawcmd)) == NULL) {
    {
      runtime_exception("damn, unable to allocate memory [FILE: %s LINE: %u]",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/"
                        "janus/refs/heads/master/src/os_cmds.c",
                        288);
    }
  };
  if ((p = strchr(tofree, (int)'~')) == NULL) {
    free(tofree);
    if (((ret) = strdup(original_rawcmd)) == NULL) {
      {
        runtime_exception("damn, unable to allocate memory [FILE: %s LINE: %u]",
                          "/scratch/repos/new/home/jordi_armengol_estape/"
                          "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                          "evilaliv3/janus/refs/heads/master/src/os_cmds.c",
                          294);
      }
    };
    return ret;
  }
  last_p = tofree;
  do {
    *(p++) = 0x00;
    memcpy(&buffer[j], last_p, strlen(last_p));
    j += strlen(last_p);
    memcpy(&buffer[j], get_sysmap_str(*p), strlen(get_sysmap_str(*p)));
    j += strlen(get_sysmap_str(*p));
    *(p++) = 0x00;
    last_p = p;
    p = strchr(p, '~');
  } while (p != NULL);
  memcpy(&buffer[j], last_p, strlen(last_p));
  j += strlen(last_p);
  buffer[j] = 0x00;
  free(tofree);
  if (((ret) = strdup(buffer)) == NULL) {
    {
      runtime_exception("damn, unable to allocate memory [FILE: %s LINE: %u]",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/"
                        "janus/refs/heads/master/src/os_cmds.c",
                        329);
    }
  };
  return ret;
}


x86 assembly (clang, -O0):
<expand_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
movb   $0x20,-0x130(%rbp)
movq   $0x0,-0x138(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e3 <expand_command+0x63>
lea    0xe2e(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x120,%edx
call   1050 <runtime_exception@plt>
mov    -0x20(%rbp),%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1244 <expand_command+0xc4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1237 <expand_command+0xb7>
lea    0xdda(%rip),%rdi
lea    0xe07(%rip),%rsi
mov    $0x126,%edx
call   1050 <runtime_exception@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1407 <expand_command+0x287>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
lea    -0x130(%rbp),%rax
add    -0x138(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x158(%rbp),%rdi
mov    -0x150(%rbp),%rsi
mov    %rax,%rdx
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
add    -0x138(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rax
add    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,-0x140(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %rax,%rdx
call   1090 <memcpy@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
add    -0x138(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124c <expand_command+0xcc>
lea    -0x130(%rbp),%rax
add    -0x138(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x168(%rbp),%rdi
mov    -0x160(%rbp),%rsi
mov    %rax,%rdx
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
add    -0x138(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    -0x130(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    13ff <expand_command+0x27f>
lea    0xc12(%rip),%rdi
lea    0xc3f(%rip),%rsi
mov    $0x149,%edx
call   1050 <runtime_exception@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_command>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x20,(%rsp)
call   1090 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1216 <expand_command+0xa6>
lea    0xdfb(%rip),%rdi
lea    0xe28(%rip),%rsi
mov    $0x120,%edx
call   1050 <runtime_exception@plt>
mov    %r14,%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     132d <expand_command+0x1bd>
mov    %rax,%r15
xor    %r12d,%r12d
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%r15)
lea    (%rsp,%r12,1),%r13
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
add    %r12,%rbx
lea    (%rsp,%rbx,1),%r12
movsbl 0x1(%r15),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,%r13
movsbl 0x1(%r15),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1080 <memcpy@plt>
movsbl 0x1(%r15),%edi
call   1040 <get_sysmap_str@plt>
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %rax,%r12
add    %rbx,%r12
movb   $0x0,0x1(%r15)
mov    %r15,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x7e,%esi
call   1070 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1240 <expand_command+0xd0>
lea    (%rsp,%r12,1),%r15
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
add    %r12,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rsp,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
jne    135c <expand_command+0x1ec>
lea    0xce1(%rip),%rdi
lea    0xd0e(%rip),%rsi
mov    $0x149,%edx
jmp    1355 <expand_command+0x1e5>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1090 <strdup@plt>
test   %rax,%rax
jne    135c <expand_command+0x1ec>
lea    0xcb7(%rip),%rdi
lea    0xce4(%rip),%rsi
mov    $0x126,%edx
call   1050 <runtime_exception@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [52 x i8] c"damn, unable to allocate memory [FILE: %s LINE: %u]\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/janus/refs/heads/master/src/os_cmds.c\00"
define i8* @expand_command(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i64
store i8* %0, i8** %3
%10 = bitcast [256 x i8]* %8 to i8*
%11 = bitcast i8* %10 to <{ i8, [255 x i8] }>*
%12 = getelementptr inbounds <{ i8, [255 x i8] }>, <{ i8, [255 x i8] }>* %11, i32 0, i32 0
store i8 32, i8* %12
store i64 0, i64* %9
%13 = load i8*, i8** %3
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 288)
br label %18
18: ; preds = %16, %1
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 126)
store i8* %20, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %4
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 294)
br label %30
30: ; preds = %28, %22
%31 = load i8*, i8** %4
store i8* %31, i8** %2
br label %93
32: ; preds = %18
%33 = load i8*, i8** %5
store i8* %33, i8** %6
br label %34
34: ; preds = %68, %32
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
store i8 0, i8* %35
%37 = load i64, i64* %9
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %37
%39 = load i8*, i8** %6
%40 = load i8*, i8** %6
%41 = call i64 @strlen(i8* %40)
%42 = call i32 @memcpy(i8* %38, i8* %39, i64 %41)
%43 = load i8*, i8** %6
%44 = call i64 @strlen(i8* %43)
%45 = load i64, i64* %9
%46 = add i64 %45, %44
store i64 %46, i64* %9
%47 = load i64, i64* %9
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %47
%49 = load i8*, i8** %7
%50 = load i8, i8* %49
%51 = call i8* @get_sysmap_str(i8 signext %50)
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = call i8* @get_sysmap_str(i8 signext %53)
%55 = call i64 @strlen(i8* %54)
%56 = call i32 @memcpy(i8* %48, i8* %51, i64 %55)
%57 = load i8*, i8** %7
%58 = load i8, i8* %57
%59 = call i8* @get_sysmap_str(i8 signext %58)
%60 = call i64 @strlen(i8* %59)
%61 = load i64, i64* %9
%62 = add i64 %61, %60
store i64 %62, i64* %9
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %7
store i8 0, i8* %63
%65 = load i8*, i8** %7
store i8* %65, i8** %6
%66 = load i8*, i8** %7
%67 = call i8* @strchr(i8* %66, i8 signext 126)
store i8* %67, i8** %7
br label %68
68: ; preds = %34
%69 = load i8*, i8** %7
%70 = icmp ne i8* %69, null
br i1 %70, label %34, label %71
71: ; preds = %68
%72 = load i64, i64* %9
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %72
%74 = load i8*, i8** %6
%75 = load i8*, i8** %6
%76 = call i64 @strlen(i8* %75)
%77 = call i32 @memcpy(i8* %73, i8* %74, i64 %76)
%78 = load i8*, i8** %6
%79 = call i64 @strlen(i8* %78)
%80 = load i64, i64* %9
%81 = add i64 %80, %79
store i64 %81, i64* %9
%82 = load i64, i64* %9
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %82
store i8 0, i8* %83
%84 = load i8*, i8** %5
%85 = call i32 @free(i8* %84)
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%87 = call i8* @strdup(i8* %86)
store i8* %87, i8** %4
%88 = icmp eq i8* %87, null
br i1 %88, label %89, label %91
89: ; preds = %71
%90 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 329)
br label %91
91: ; preds = %89, %71
%92 = load i8*, i8** %4
store i8* %92, i8** %2
br label %93
93: ; preds = %91, %30
%94 = load i8*, i8** %2
ret i8* %94
}

LLVM IR (-O2):
@.str = [52 x i8] c"damn, unable to allocate memory [FILE: %s LINE: %u]\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/janus/refs/heads/master/src/os_cmds.c\00"
define noalias i8* @expand_command(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 32, i8* %3
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 288)
br label %8
8: ; preds = %6, %1
%9 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 126)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = tail call i32 @free(i8* %4)
%13 = tail call i8* @strdup(i8* %0)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = tail call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 294)
br label %53
17: ; preds = %8, %17
%18 = phi i8* [ %38, %17 ], [ %4, %8 ]
%19 = phi i8* [ %39, %17 ], [ %9, %8 ]
%20 = phi i64 [ %37, %17 ], [ 0, %8 ]
%21 = getelementptr inbounds i8, i8* %19, i64 1
store i8 0, i8* %19
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %20
%23 = call i64 @strlen(i8* dereferenceable(1) %18)
%24 = call i32 @memcpy(i8* %22, i8* %18, i64 %23)
%25 = call i64 @strlen(i8* dereferenceable(1) %18)
%26 = add i64 %25, %20
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %21
%29 = call i8* @get_sysmap_str(i8 signext %28)
%30 = load i8, i8* %21
%31 = call i8* @get_sysmap_str(i8 signext %30)
%32 = call i64 @strlen(i8* dereferenceable(1) %31)
%33 = call i32 @memcpy(i8* %27, i8* %29, i64 %32)
%34 = load i8, i8* %21
%35 = call i8* @get_sysmap_str(i8 signext %34)
%36 = call i64 @strlen(i8* dereferenceable(1) %35)
%37 = add i64 %36, %26
%38 = getelementptr inbounds i8, i8* %19, i64 2
store i8 0, i8* %21
%39 = call i8* @strchr(i8* %38, i8 signext 126)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %17
41: ; preds = %17
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %37
%43 = call i64 @strlen(i8* %38)
%44 = call i32 @memcpy(i8* %42, i8* %38, i64 %43)
%45 = call i64 @strlen(i8* %38)
%46 = add i64 %45, %37
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i32 @free(i8* %4)
%49 = call i8* @strdup(i8* %3)
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %41
%52 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 329)
br label %53
53: ; preds = %41, %51, %11, %15
%54 = phi i8* [ null, %15 ], [ %13, %11 ], [ null, %51 ], [ %49, %41 ]
ret i8* %54
}