#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 /*<<< orphan*/ execlp(char *, char *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void catwc(const char *arg) {
  pid_t pid = fork();
  if (!pid)
    execlp("cat", "cat", arg, NULL);
  else {
    int status;
    waitpid(pid, &status, 0);
    execlp("wc", "wc", arg, NULL);
  }
}


x86 assembly (clang, -O0):
<catwc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116c <catwc+0x3c>
mov    -0x8(%rbp),%rdx
lea    0xea5(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1040 <execlp@plt>
jmp    1191 <catwc+0x61>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    -0x8(%rbp),%rdx
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1040 <execlp@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catwc>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     116b <catwc+0x3b>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1030 <waitpid@plt>
lea    0xeac(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <execlp@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8e(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
add    $0x10,%rsp
pop    %rbx
jmp    1040 <execlp@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"cat\00"
@.str.1 = [3 x i8] c"wc\00"
define void @catwc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9, i32* null)
br label %16
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @waitpid(i32 %12, i32* %4, i32 0)
%14 = load i8*, i8** %2
%15 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32* null)
br label %16
16: ; preds = %11, %8
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"cat\00"
@.str.1 = [3 x i8] c"wc\00"
define void @catwc(i8* %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0, i32* null)
br label %11
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = call i32 @waitpid(i32 %3, i32* %2, i32 0)
%10 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
br label %11
11: ; preds = %7, %5
ret void
}