cmd_system(cmd) char *cmd;
{
  int retval;
  if (!cmd)
    cmd = getenv("SHELL");
  if (!cmd)
    cmd = "/bin/sh";
  retval = system(cmd);
  if (retval != 0)
    message("system(\"%s\") returned %d.", cmd, retval);
}


x86 assembly (clang, -O0):
<cmd_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115b <cmd_system+0x2b>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <getenv@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <cmd_system+0x41>
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1050 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119e <cmd_system+0x6e>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <message@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_system>:
push   %rbx
test   %rdi,%rdi
jne    1147 <cmd_system+0x17>
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1030 <getenv@plt>
movslq %eax,%rdi
test   %rdi,%rdi
lea    0xeb5(%rip),%rbx
cmovne %rdi,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <system@plt>
test   %eax,%eax
je     1176 <cmd_system+0x46>
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <message@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [26 x i8] c"system(\22%s\22) returned %d.\00"
define i32 @cmd_system(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
br label %11
11: ; preds = %7, %1
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %15
15: ; preds = %14, %11
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @message to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %21, i32 %22)
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [26 x i8] c"system(\22%s\22) returned %d.\00"
define i32 @cmd_system(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i8*
br label %7
7: ; preds = %3, %1
%8 = phi i8* [ %0, %1 ], [ %6, %3 ]
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = tail call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @message to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %11)
br label %15
15: ; preds = %13, %7
ret i32 undef
}