// File: /workspace/github_c_makefile_star2_O3/info-telecom-strasbourg[P]code-generator/src/utils.cpp
// Function: _execute__[abi:cxx11](int*, unsigned long*, char const*, char* const*)
string __execute__ (int * exit_code, size_t * len, const char * path, 
	char * const cmd []) {

	int err_reason, pipefd [2];
	
	string cmd_output_str;
	char buf [BUFSIZ];
	
	FILE * cmd_output;

	size_t nbytes = 0;
	*len = 0;

	CHECK (pipe (pipefd));

	switch (fork ()) {
	case -1 :
		interupt (1, "fork failed.");
		break;
	
	case 0 :
		CHECK (dup2 (pipefd[1], STDOUT_FILENO));
		CHECK (close (pipefd[0]));
		CHECK (close (pipefd[1]));
		execv (path, cmd);
		fprintf(stderr, "execv error: failed command is:\n");
		while ( *cmd ) 
			{ fprintf (stderr, "%s ", *cmd++); }
		interupt (1, "\nexecv error: path is: \n\"%s\"", path);
		break;

	default :
		CHECK (wait (&err_reason));
		CHECK (close (pipefd[1]));
		CHECKN (cmd_output = fdopen (pipefd[0], "r"));
		*exit_code = WEXITSTATUS (err_reason);
	
		while ((nbytes = fread(buf, 1, sizeof(buf), cmd_output)) == BUFSIZ) {
			for (size_t i = 0; i < BUFSIZ; i++)
        		cmd_output_str.push_back(buf[i]);
		}
		
		for (size_t i = 0; i < nbytes; i++)
     		cmd_output_str.push_back(buf[i]);
	}

	if (fclose(cmd_output) == EOF)
		interupt (1, "fclose() failed.");

	if (cmd_output_str.empty())
		return "";

	return cmd_output_str;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2038, %rsp           # imm = 0x2038
movq %r8, %r14
movq %rcx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
xorl %eax, %eax
movq %rax, -0x8(%rbp)
movb $0x0, (%rbp)
movq %rax, (%rdx)
leaq 0x4(%rsp), %rdi
callq 0x22a0
cmpl $-0x1, %eax
je 0x5d89
callq 0x2050
testl %eax, %eax
je 0x5d92
cmpl $-0x1, %eax
je 0x5dae
leaq 0xc(%rsp), %rdi
callq 0x2260
cmpl $-0x1, %eax
je 0x5db7
movl 0x8(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
je 0x5df7
movl 0x4(%rsp), %edi
leaq 0x1673(%rip), %rsi      # 0x72c8
callq 0x2200
testq %rax, %rax
je 0x5dc0
movq %rax, %r14
movzbl 0xd(%rsp), %eax
movl %eax, (%r15)
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
movl $0x2000, %edx           # imm = 0x2000
movq %r14, %rcx
callq 0x22d0
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x5cde
xorl %ebp, %ebp
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movsbl 0x30(%rsp,%rbp), %esi
movq %r12, %rdi
callq 0x2150
incq %rbp
cmpq $0x2000, %rbp           # imm = 0x2000
jne 0x5c99
movl $0x1, %esi
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movq %r14, %rcx
callq 0x22d0
movl $0x0, %ebp
cmpq $0x2000, %rax           # imm = 0x2000
je 0x5c99
movq %rax, %r15
leaq 0x20(%rsp), %rbp
jmp 0x5ce1
movq %rax, %r15
testq %r15, %r15
je 0x5d04
xorl %r13d, %r13d
leaq 0x10(%rsp), %r12
movsbl 0x30(%rsp,%r13), %esi
movq %r12, %rdi
callq 0x2150
incq %r13
cmpq %r13, %r15
jne 0x5cee
movq %r14, %rdi
callq 0x21b0
cmpl $-0x1, %eax
je 0x5dc9
movq 0x18(%rsp), %rax
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
testq %rax, %rax
je 0x5d3e
movq 0x10(%rsp), %rdx
cmpq %rbp, %rdx
je 0x5d69
movq %rdx, (%rbx)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rbx)
jmp 0x5d70
leaq 0x191e(%rip), %rdx      # 0x7663
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4110
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5d74
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
jmp 0x5d74
movups (%rbp), %xmm0
movups %xmm0, (%rcx)
movq %rax, 0x8(%rbx)
movq %rbx, %rax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c38(%rip), %rsi      # 0x79c8
jmp 0x5dfe
movl 0x8(%rsp), %edi
movl $0x1, %esi
callq 0x2180
cmpl $-0x1, %eax
jne 0x5dd2
leaq 0x1c37(%rip), %rsi      # 0x79e3
jmp 0x5dfe
leaq 0x1c21(%rip), %rsi      # 0x79d6
jmp 0x5dfe
leaq 0x1cab(%rip), %rsi      # 0x7a69
jmp 0x5dfe
leaq 0x1cb5(%rip), %rsi      # 0x7a7c
jmp 0x5dfe
leaq 0x1cd1(%rip), %rsi      # 0x7aa1
jmp 0x5dfe
movl 0x4(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
jne 0x5de9
leaq 0x1c1c(%rip), %rsi      # 0x7a03
jmp 0x5dfe
movl 0x8(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
jne 0x5e0a
leaq 0x1c17(%rip), %rsi      # 0x7a15
movl $0x1, %edi
xorl %eax, %eax
callq 0x5adc
movq %r12, %rdi
movq %r14, %rsi
callq 0x2692
jmp 0x5e1b
jmp 0x5e1b
jmp 0x5e1b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x5e3a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x2340