#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 */
int /*<<< orphan*/ execl(char const *, char const *, char *, char const *,
                         int /*<<< orphan*/ *);
char *getenv(char *);
void a_exec(const char *cmd) {
  static const char *shell = NULL;
  if (!shell && !(shell = getenv("SHELL")))
    shell = "/bin/sh";
  execl(shell, shell, "-c", cmd, NULL);
}


x86 assembly (clang, -O0):
<a_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2f04(%rip)
jne    1165 <a_exec+0x45>
lea    0xebf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2eeb(%rip)
cmp    $0x0,%rax
jne    1165 <a_exec+0x45>
lea    0xea8(%rip),%rax
mov    %rax,0x2ed3(%rip)
mov    0x2ecc(%rip),%rdi
mov    0x2ec5(%rip),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe90(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <execl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_exec>:
push   %rbx
mov    %rdi,%rbx
mov    0x2f0d(%rip),%rdi
test   %rdi,%rdi
jne    1151 <a_exec+0x31>
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xec0(%rip),%rdi
cmovne %rax,%rdi
mov    %rdi,0x2ee7(%rip)
lea    0xeb6(%rip),%rdx
mov    %rdi,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
pop    %rbx
jmp    1040 <execl@plt>

LLVM IR (-O0):
@a_exec.shell = internal global i8* null
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
define void @a_exec(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** @a_exec.shell
%4 = icmp ne i8* %3, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** @a_exec.shell
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** @a_exec.shell
br label %9
9: ; preds = %8, %5, %1
%10 = load i8*, i8** @a_exec.shell
%11 = load i8*, i8** @a_exec.shell
%12 = load i8*, i8** %2
%13 = call i32 @execl(i8* %10, i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32* null)
ret void
}

LLVM IR (-O2):
@a_exec.shell = internal unnamed_addr global i8* null
@.str = [6 x i8] c"SHELL\00"
@.str.1 = [8 x i8] c"/bin/sh\00"
@.str.2 = [3 x i8] c"-c\00"
define void @a_exec(i8* %0) {
%2 = load i8*, i8** @a_exec.shell
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5
store i8* %7, i8** @a_exec.shell
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ %7, %4 ], [ %2, %1 ]
%10 = tail call i32 @execl(i8* %9, i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
ret void
}