#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 *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int alert_execute(char *cmd) {
  int st;
  switch (fork()) {
  case -1:
    fprintf(stderr, "failed in fork.");
    break;
  case 0:
    switch (fork()) {
    case -1:
      fprintf(stderr, "failed in fork.");
      break;
    case 0: {
      char *shell = getenv("SHELL");
      execl(shell, shell, "-c", cmd, (char *)0);
      fprintf(stderr, "execl: couldn't exec (%s)", shell);
      exit(1);
    } break;
    default:
      break;
    }
    exit(0);
    break;
  default:
    wait(&st);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<alert_execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1196 <alert_execute+0x36>
jmp    1186 <alert_execute+0x26>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     11b2 <alert_execute+0x52>
jmp    1256 <alert_execute+0xf6>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    125f <alert_execute+0xff>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0xffffffff,%eax
je     11dc <alert_execute+0x7c>
jmp    11cc <alert_execute+0x6c>
mov    -0x20(%rbp),%eax
test   %eax,%eax
je     11f8 <alert_execute+0x98>
jmp    124a <alert_execute+0xea>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    124f <alert_execute+0xef>
lea    0xe11(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xdfb(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execl@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    124f <alert_execute+0xef>
xor    %edi,%edi
call   1050 <exit@plt>
lea    -0xc(%rbp),%rdi
call   1070 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alert_execute>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     1183 <alert_execute+0x23>
test   %eax,%eax
je     11a4 <alert_execute+0x44>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
jmp    119a <alert_execute+0x3a>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11d2 <alert_execute+0x72>
cmp    $0xffffffff,%eax
jne    11cb <alert_execute+0x6b>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe2e(%rip),%rdx
mov    %rax,%rdi
mov    %rax,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"failed in fork.\00"
@.str.1 = [6 x i8] c"SHELL\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [26 x i8] c"execl: couldn't exec (%s)\00"
define i32 @alert_execute(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i32 (...) @fork()
switch i32 %5, label %27 [
i32 -1, label %6
i32 0, label %9
]
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %29
9: ; preds = %1
%10 = call i32 (...) @fork()
switch i32 %10, label %24 [
i32 -1, label %11
i32 0, label %14
]
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %25
14: ; preds = %9
%15 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = load i8*, i8** %2
%19 = call i32 @execl(i8* %16, i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* null)
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %9
br label %25
25: ; preds = %24, %11
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %1
%28 = call i32 @wait(i32* %3)
br label %29
29: ; preds = %27, %6
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"failed in fork.\00"
@.str.1 = [6 x i8] c"SHELL\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [26 x i8] c"execl: couldn't exec (%s)\00"
define i32 @alert_execute(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
switch i32 %4, label %21 [
i32 -1, label %5
i32 0, label %8
]
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %1
%9 = tail call i32 (...) @fork()
switch i32 %9, label %19 [
i32 -1, label %10
i32 0, label %13
]
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %19
13: ; preds = %8
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @execl(i8* %14, i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* null)
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8, %10
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %1
%22 = call i32 @wait(i32* %2)
br label %23
23: ; preds = %21, %5
ret i32 0
}