// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20e0, %rsp           # imm = 0x20E0
movq %rdi, -0x20a8(%rbp)
movq %rdi, %rax
movq %rax, -0x20a0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x33c0
movq $0x0, -0x2070(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
leaq -0x34(%rbp), %rdi
callq 0x33b0
cmpl $-0x1, %eax
jne 0x839b
leaq 0x2644(%rip), %rsi      # 0xa9b8
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x8382
jmp 0x839b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2078(%rbp)
movl %eax, -0x207c(%rbp)
jmp 0x8765
jmp 0x839d
jmp 0x839f
callq 0x3070
movl %eax, %ecx
movl %ecx, -0x20ac(%rbp)
subl $-0x1, %eax
je 0x83c2
jmp 0x83b3
movl -0x20ac(%rbp), %eax
testl %eax, %eax
je 0x83dc
jmp 0x84f4
leaq 0x25fd(%rip), %rsi      # 0xa9c6
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x83d7
jmp 0x8686
jmp 0x83de
movl -0x30(%rbp), %edi
movl $0x1, %esi
callq 0x3220
cmpl $-0x1, %eax
jne 0x8407
leaq 0x25dc(%rip), %rsi      # 0xa9d3
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x8405
jmp 0x8407
jmp 0x8409
jmp 0x840b
jmp 0x840d
movl -0x34(%rbp), %edi
callq 0x34f0
movl %eax, -0x20b0(%rbp)
jmp 0x841d
movl -0x20b0(%rbp), %eax
cmpl $-0x1, %eax
jne 0x843f
leaq 0x25c4(%rip), %rsi      # 0xa9f3
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x843d
jmp 0x843f
jmp 0x8441
jmp 0x8443
jmp 0x8445
movl -0x30(%rbp), %edi
callq 0x34f0
movl %eax, -0x20b4(%rbp)
jmp 0x8455
movl -0x20b4(%rbp), %eax
cmpl $-0x1, %eax
jne 0x8477
leaq 0x259e(%rip), %rsi      # 0xaa05
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x8475
jmp 0x8477
jmp 0x8479
jmp 0x847b
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3210
movq 0x5b41(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
leaq 0x257e(%rip), %rsi      # 0xaa17
movb $0x0, %al
callq 0x33e0
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
je 0x84d6
movq 0x5b1f(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x28(%rbp)
movq (%rax), %rdx
leaq 0x256b(%rip), %rsi      # 0xaa38
movb $0x0, %al
callq 0x33e0
jmp 0x84a0
movq -0x20(%rbp), %rdx
leaq 0x255b(%rip), %rsi      # 0xaa3c
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x84ef
jmp 0x8686
jmp 0x84f6
leaq -0x2c(%rbp), %rdi
callq 0x3340
movl %eax, -0x20b8(%rbp)
jmp 0x8507
movl -0x20b8(%rbp), %eax
cmpl $-0x1, %eax
jne 0x8529
leaq 0x2540(%rip), %rsi      # 0xaa59
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x8527
jmp 0x8529
jmp 0x852b
jmp 0x852d
jmp 0x852f
movl -0x30(%rbp), %edi
callq 0x34f0
movl %eax, -0x20bc(%rbp)
jmp 0x853f
movl -0x20bc(%rbp), %eax
cmpl $-0x1, %eax
jne 0x8561
leaq 0x24b4(%rip), %rsi      # 0xaa05
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x855f
jmp 0x8561
jmp 0x8563
jmp 0x8565
jmp 0x8567
movl -0x34(%rbp), %edi
leaq 0x1d57(%rip), %rsi      # 0xa2c8
callq 0x32a0
movq %rax, -0x2068(%rbp)
cmpq $0x0, %rax
jne 0x859a
leaq 0x24e2(%rip), %rsi      # 0xaa6c
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x8598
jmp 0x859a
jmp 0x859c
jmp 0x859e
movl -0x2c(%rbp), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
sarl $0x8, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x2068(%rbp), %rcx
leaq -0x2060(%rbp), %rdi
movl $0x1, %esi
movl $0x2000, %edx           # imm = 0x2000
callq 0x3400
movq %rax, -0x20c8(%rbp)
jmp 0x85d6
movq -0x20c8(%rbp), %rax
movq %rax, -0x2070(%rbp)
cmpq $0x2000, %rax           # imm = 0x2000
jne 0x8639
movq $0x0, -0x2088(%rbp)
cmpq $0x2000, -0x2088(%rbp) # imm = 0x2000
jae 0x8634
movq -0x2088(%rbp), %rax
movsbl -0x2060(%rbp,%rax), %esi
leaq -0x58(%rbp), %rdi
callq 0x31d0
jmp 0x861e
jmp 0x8620
movq -0x2088(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2088(%rbp)
jmp 0x85f7
jmp 0x85b0
movq $0x0, -0x2090(%rbp)
movq -0x2090(%rbp), %rax
cmpq -0x2070(%rbp), %rax
jae 0x8684
movq -0x2090(%rbp), %rax
movsbl -0x2060(%rbp,%rax), %esi
leaq -0x58(%rbp), %rdi
callq 0x31d0
jmp 0x866e
jmp 0x8670
movq -0x2090(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2090(%rbp)
jmp 0x8644
jmp 0x8686
movq -0x2068(%rbp), %rdi
callq 0x3240
movl %eax, -0x20cc(%rbp)
jmp 0x869a
movl -0x20cc(%rbp), %eax
cmpl $-0x1, %eax
jne 0x86bc
leaq 0x23e5(%rip), %rsi      # 0xaa91
xorl %eax, %eax
movl $0x1, %edi
callq 0x8190
jmp 0x86ba
jmp 0x86bc
leaq -0x58(%rbp), %rdi
callq 0x3470
testb $0x1, %al
jne 0x86cb
jmp 0x8732
leaq -0x2091(%rbp), %rdi
movq %rdi, -0x20d8(%rbp)
callq 0x34a0
movq -0x20a8(%rbp), %rdi
movq -0x20d8(%rbp), %rdx
leaq 0x1f70(%rip), %rsi      # 0xa663
callq 0x4f80
jmp 0x86fa
leaq -0x2091(%rbp), %rdi
callq 0x32c0
movl $0x1, -0x2098(%rbp)
jmp 0x874c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2078(%rbp)
movl %eax, -0x207c(%rbp)
leaq -0x2091(%rbp), %rdi
callq 0x32c0
jmp 0x8765
movq -0x20a8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3130
movl $0x1, -0x2098(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3140
movq -0x20a0(%rbp), %rax
addq $0x20e0, %rsp           # imm = 0x20E0
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x3140
movq -0x2078(%rbp), %rdi
callq 0x3490
nopw (%rax,%rax)