#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 */
struct ipr_ioa {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cmd_to_args(char *, int *, char ***);
int /*<<< orphan*/ free(char **);
int mr4(struct ipr_ioa *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int parse_cmd(struct ipr_ioa *, int, char **);
int exec_shell_cmd(struct ipr_ioa *ioa, char *cmd) {
  char **argv = NULL;
  int argc, rc;
  if (!cmd_to_args(cmd, &argc, &argv))
    return mr4(ioa, 0, NULL);
  rc = parse_cmd(ioa, argc, argv);
  free(argv);
  return rc;
}


x86 assembly (clang, -O0):
<exec_shell_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <cmd_to_args@plt>
cmp    $0x0,%eax
jne    1189 <exec_shell_cmd+0x49>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <mr4@plt>
mov    %eax,-0x4(%rbp)
jmp    11ab <exec_shell_cmd+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <parse_cmd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_shell_cmd>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
lea    0xc(%rsp),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1060 <cmd_to_args@plt>
test   %eax,%eax
je     1184 <exec_shell_cmd+0x44>
mov    0xc(%rsp),%esi
mov    (%rsp),%rdx
mov    %rbx,%rdi
call   1050 <parse_cmd@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    1192 <exec_shell_cmd+0x52>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <mr4@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ipr_ioa = type { i32 }
define i32 @exec_shell_cmd(%struct.ipr_ioa* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.ipr_ioa*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store %struct.ipr_ioa* %0, %struct.ipr_ioa** %4
store i8* %1, i8** %5
store i8** null, i8*** %6
%9 = load i8*, i8** %5
%10 = call i32 @cmd_to_args(i8* %9, i32* %7, i8*** %6)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load %struct.ipr_ioa*, %struct.ipr_ioa** %4
%14 = call i32 @mr4(%struct.ipr_ioa* %13, i32 0, i32* null)
store i32 %14, i32* %3
br label %23
15: ; preds = %2
%16 = load %struct.ipr_ioa*, %struct.ipr_ioa** %4
%17 = load i32, i32* %7
%18 = load i8**, i8*** %6
%19 = call i32 @parse_cmd(%struct.ipr_ioa* %16, i32 %17, i8** %18)
store i32 %19, i32* %8
%20 = load i8**, i8*** %6
%21 = call i32 @free(i8** %20)
%22 = load i32, i32* %8
store i32 %22, i32* %3
br label %23
23: ; preds = %15, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.ipr_ioa = type { i32 }
define i32 @exec_shell_cmd(%struct.ipr_ioa* %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = bitcast i8*** %3 to i8*
store i8** null, i8*** %3
%6 = bitcast i32* %4 to i8*
%7 = call i32 @cmd_to_args(i8* %1, i32* %4, i8*** %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @mr4(%struct.ipr_ioa* %0, i32 0, i32* null)
br label %17
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %3
%14 = call i32 @parse_cmd(%struct.ipr_ioa* %0, i32 %12, i8** %13)
%15 = load i8**, i8*** %3
%16 = call i32 @free(i8** %15)
br label %17
17: ; preds = %11, %9
%18 = phi i32 [ %14, %11 ], [ %10, %9 ]
ret i32 %18
}