#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  pid_t pid;
  int ret = -1;
  if ((pid = fork()) == 0) {
    printf("子进程启动:\n");
    if ((ret = execlp("ps",
                      "ps"
                      " -ef",
                      NULL)) < 0) {
      printf("调用execl函数失败！\n");
      exit(-1);
    }
    printf("调用execl函数结束!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11c1 <main+0x81>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    0xe8b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11b5 <main+0x75>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jne    117d <main+0x3d>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
lea    0xe9d(%rip),%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
test   %eax,%eax
js     1181 <main+0x41>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8B\E5\90\AF\E5\8A\A8:\0A\00"
@.str.1 = [3 x i8] c"ps\00"
@.str.2 = [7 x i8] c"ps -ef\00"
@.str.3 = [28 x i8] c"\E8\B0\83\E7\94\A8execl\E5\87\BD\E6\95\B0\E5\A4\B1\E8\B4\A5\EF\BC\81\0A\00"
@.str.4 = [26 x i8] c"\E8\B0\83\E7\94\A8execl\E5\87\BD\E6\95\B0\E7\BB\93\E6\9D\9F!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i32 %12, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"ps\00"
@.str.2 = [7 x i8] c"ps -ef\00"
@str = [17 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8B\E5\90\AF\E5\8A\A8:\00"
@str.5 = [25 x i8] c"\E8\B0\83\E7\94\A8execl\E5\87\BD\E6\95\B0\E7\BB\93\E6\9D\9F!\00"
@str.6 = [27 x i8] c"\E8\B0\83\E7\94\A8execl\E5\87\BD\E6\95\B0\E5\A4\B1\E8\B4\A5\EF\BC\81\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* null)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %5
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
ret i32 0
}