// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rcx, %r14
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andq $0x0, (%rdx)
leaq 0x4(%rsp), %rdi
callq 0x22b0
cmpl $-0x1, %eax
je 0x4d2a
callq 0x2050
testl %eax, %eax
je 0x4c8d
cmpl $-0x1, %eax
je 0x4d33
leaq 0xc(%rsp), %rdi
callq 0x2260
cmpl $-0x1, %eax
je 0x4d3c
movl 0x8(%rsp), %edi
callq 0x23c0
cmpl $-0x1, %eax
je 0x4d21
movl 0x4(%rsp), %edi
leaq 0x174c(%rip), %rsi      # 0x62c8
callq 0x2200
testq %rax, %rax
je 0x4d45
movq %rax, %r14
movzbl 0xd(%rsp), %eax
movl %eax, (%r12)
leaq 0x30(%rsp), %r15
pushq $0x1
popq %r12
leaq 0x10(%rsp), %r13
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x22f0
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x4bdc
xorl %ebp, %ebp
cmpq $0x2000, %rbp           # imm = 0x2000
je 0x4ba4
movsbl 0x30(%rsp,%rbp), %esi
movq %r13, %rdi
callq 0x2160
incq %rbp
jmp 0x4bc1
movq %rax, %rbp
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
cmpq %r12, %rbp
je 0x4bff
movsbl 0x30(%rsp,%r12), %esi
movq %r15, %rdi
callq 0x2160
incq %r12
jmp 0x4be7
movq %r14, %rdi
callq 0x21c0
cmpl $-0x1, %eax
je 0x4d60
movq 0x18(%rsp), %rax
testq %rax, %rax
leaq 0x20(%rsp), %rsi
je 0x4c3e
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
movq 0x10(%rsp), %rdx
cmpq %rsi, %rdx
je 0x4c54
movq %rdx, (%rbx)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rbx)
jmp 0x4c5a
leaq 0x1a1e(%rip), %rsi      # 0x6663
leaq 0x3(%rsp), %rdx
movq %rbx, %rdi
callq 0x34ea
jmp 0x4c6e
movups (%rsi), %xmm0
movups %xmm0, (%rcx)
movq %rax, 0x8(%rbx)
movq %rsi, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x20c0
movq %rbx, %rax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%rsp), %edi
pushq $0x1
popq %rsi
callq 0x21a0
cmpl $-0x1, %eax
je 0x4d4e
movl 0x4(%rsp), %edi
callq 0x23c0
cmpl $-0x1, %eax
je 0x4d57
movl 0x8(%rsp), %edi
callq 0x23c0
cmpl $-0x1, %eax
je 0x4d21
movq %r14, %rdi
movq %r15, %rsi
callq 0x2190
movq 0x42fc(%rip), %r12      # 0x8fd0
movq (%r12), %rcx
leaq 0x1d48(%rip), %rdi      # 0x6a27
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x23a0
leaq 0x1d57(%rip), %rbx      # 0x6a48
movq (%r15), %rdx
testq %rdx, %rdx
je 0x4d0d
movq (%r12), %rdi
addq $0x8, %r15
movq %rbx, %rsi
xorl %eax, %eax
callq 0x22e0
jmp 0x4cf1
leaq 0x1d38(%rip), %rsi      # 0x6a4c
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4a10
leaq 0x1ced(%rip), %rsi      # 0x6a15
jmp 0x4d67
leaq 0x1c97(%rip), %rsi      # 0x69c8
jmp 0x4d67
leaq 0x1c9c(%rip), %rsi      # 0x69d6
jmp 0x4d67
leaq 0x1d26(%rip), %rsi      # 0x6a69
jmp 0x4d67
leaq 0x1d30(%rip), %rsi      # 0x6a7c
jmp 0x4d67
leaq 0x1c8e(%rip), %rsi      # 0x69e3
jmp 0x4d67
leaq 0x1ca5(%rip), %rsi      # 0x6a03
jmp 0x4d67
leaq 0x1d3a(%rip), %rsi      # 0x6aa1
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x4a10
jmp 0x4d77
jmp 0x4d77
jmp 0x4d77
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2350