#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execlp(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int do_cmd(const char *cmd) {
  int fds[2] = {0};
  pipe(fds);
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork");
    exit(-1);
  } else if (pid == 0) {
    execlp(cmd, NULL);
    exit(-1);
  } else {
  }
  wait(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<do_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1040 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11c1 <do_cmd+0x51>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <do_cmd+0x73>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <execlp@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11e8 <do_cmd+0x78>
jmp    11ed <do_cmd+0x7d>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cmd>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     1198 <do_cmd+0x38>
je     11ae <do_cmd+0x4e>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe61(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <execlp@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
define i32 @do_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i32]
%4 = alloca i64
store i8* %0, i8** %2
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i64 (...) @fork()
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
%15 = load i64, i64* %4
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = call i32 @execlp(i8* %18, i32* null)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
br label %22
22: ; preds = %21
br label %23
23: ; preds = %22
%24 = call i32 @wait(i32* null)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
define i32 @do_cmd(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = bitcast i64* %2 to i32*
%5 = call i32 @pipe(i32* %4)
%6 = call i64 (...) @fork()
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = icmp eq i64 %6, 0
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = call i32 @execlp(i8* %0, i32* null)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %11
%17 = call i32 @wait(i32* null)
ret i32 0
}