#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 */

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ shellout_wait_ret();
int system(char const *);
int /*<<< orphan*/ ui_init();
int /*<<< orphan*/ ui_term();
int shellout(const char *cmd) {
  const char *shcmd;
  int r;
  if (cmd) {
    shcmd = cmd;
  } else {
    const char *shell = getenv("SHELL");
    if (!shell)
      shell = "sh";
    shcmd = shell;
  }
  ui_term();
  r = system(shcmd);
  shellout_wait_ret();
  ui_init();
  return r;
}


x86 assembly (clang, -O0):
<shellout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1174 <shellout+0x24>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11a2 <shellout+0x52>
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <shellout+0x4a>
lea    0xe70(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <ui_term@plt>
mov    -0x10(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <shellout_wait_ret@plt>
mov    $0x0,%al
call   1040 <ui_init@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellout>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1173 <shellout+0x23>
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe97(%rip),%rbx
cmovne %rax,%rbx
xor    %eax,%eax
call   1060 <ui_term@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <shellout_wait_ret@plt>
xor    %eax,%eax
call   1040 <ui_init@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [3 x i8] c"sh\00"
define i32 @shellout(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %2
store i8* %9, i8** %3
br label %17
10: ; preds = %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %15
15: ; preds = %14, %10
%16 = load i8*, i8** %5
store i8* %16, i8** %3
br label %17
17: ; preds = %15, %8
%18 = call i32 (...) @ui_term()
%19 = load i8*, i8** %3
%20 = call i32 @system(i8* %19)
store i32 %20, i32* %4
%21 = call i32 (...) @shellout_wait_ret()
%22 = call i32 (...) @ui_init()
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [3 x i8] c"sh\00"
define i32 @shellout(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ %6, %3 ], [ %0, %1 ]
%9 = tail call i32 (...) @ui_term()
%10 = tail call i32 @system(i8* %8)
%11 = tail call i32 (...) @shellout_wait_ret()
%12 = tail call i32 (...) @ui_init()
ret i32 %10
}