// File: /workspace/github_c_makefile_star2_O1/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 0x5dce
callq 0x2050
testl %eax, %eax
je 0x5dd7
cmpl $-0x1, %eax
je 0x5df3
leaq 0xc(%rsp), %rdi
callq 0x2260
cmpl $-0x1, %eax
je 0x5dfc
movl 0x8(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
je 0x5e3c
movl 0x4(%rsp), %edi
leaq 0x1641(%rip), %rsi      # 0x72c8
callq 0x2200
testq %rax, %rax
je 0x5e05
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 0x5d10
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 0x5ccb
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 0x5ccb
movq %rax, %r15
leaq 0x20(%rsp), %rbp
jmp 0x5d13
movq %rax, %r15
testq %r15, %r15
je 0x5d36
xorl %r13d, %r13d
leaq 0x10(%rsp), %r12
movsbl 0x30(%rsp,%r13), %esi
movq %r12, %rdi
callq 0x2150
incq %r13
cmpq %r13, %r15
jne 0x5d20
movq %r14, %rdi
callq 0x21b0
cmpl $-0x1, %eax
je 0x5e0e
movq 0x18(%rsp), %rax
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
testq %rax, %rax
je 0x5d70
movq 0x10(%rsp), %rdx
cmpq %rbp, %rdx
je 0x5d84
movq %rdx, (%rbx)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rbx)
jmp 0x5d8b
leaq 0x18ec(%rip), %rdx      # 0x7663
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4100
jmp 0x5da2
movups (%rbp), %xmm0
movups %xmm0, (%rcx)
movq %rax, 0x8(%rbx)
movq %rbp, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5db9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bf3(%rip), %rsi      # 0x79c8
jmp 0x5e43
movl 0x8(%rsp), %edi
movl $0x1, %esi
callq 0x2180
cmpl $-0x1, %eax
jne 0x5e17
leaq 0x1bf2(%rip), %rsi      # 0x79e3
jmp 0x5e43
leaq 0x1bdc(%rip), %rsi      # 0x79d6
jmp 0x5e43
leaq 0x1c66(%rip), %rsi      # 0x7a69
jmp 0x5e43
leaq 0x1c70(%rip), %rsi      # 0x7a7c
jmp 0x5e43
leaq 0x1c8c(%rip), %rsi      # 0x7aa1
jmp 0x5e43
movl 0x4(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
jne 0x5e2e
leaq 0x1bd7(%rip), %rsi      # 0x7a03
jmp 0x5e43
movl 0x8(%rsp), %edi
callq 0x23a0
cmpl $-0x1, %eax
jne 0x5e4f
leaq 0x1bd2(%rip), %rsi      # 0x7a15
movl $0x1, %edi
xorl %eax, %eax
callq 0x5b0c
movq %r12, %rdi
movq %r14, %rsi
callq 0x2692
jmp 0x5e60
jmp 0x5e60
jmp 0x5e60
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x5e7f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x2340