#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*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ util_shellCmd(char const *);
int apps_opt_cmdline() {
  char cmd[128] = "";
  char *shell = getenv("SHELL");
  if (shell == NULL) {
    shell = "/bin/bash";
  }
  printf("Enter a command to execute using %s: ", shell);
  scanf(" %[^\n]", (char *)&cmd);
  util_shellCmd((const char *)&cmd);
  return 0;
}


x86 assembly (clang, -O0):
<apps_opt_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    119a <apps_opt_cmdline+0x4a>
lea    0xe73(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x80(%rbp),%rdi
call   1060 <util_shellCmd@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apps_opt_cmdline>:
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe87(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe7e(%rip),%rsi
cmovne %rax,%rsi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1050 <util_shellCmd@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [10 x i8] c"/bin/bash\00"
@.str.2 = [38 x i8] c"Enter a command to execute using %s: \00"
@.str.3 = [7 x i8] c" %[^\0A]\00"
define i32 @apps_opt_cmdline() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = bitcast [128 x i8]* %1 to i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %8
8: ; preds = %7, %0
%9 = load i8*, i8** %2
%10 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = bitcast [128 x i8]* %1 to i8*
%12 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = bitcast [128 x i8]* %1 to i8*
%14 = call i32 @util_shellCmd(i8* %13)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [10 x i8] c"/bin/bash\00"
@.str.2 = [38 x i8] c"Enter a command to execute using %s: \00"
@.str.3 = [7 x i8] c" %[^\0A]\00"
define i32 @apps_opt_cmdline() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = call i32 @util_shellCmd(i8* %2)
ret i32 0
}