#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ fork();
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ wait();
int main(int argc, char *argv[]) {
  if (argc > 1) {
    if (!fork()) {
      close(1);
      open("ftemp", O_WRONLY | O_CREAT | O_TRUNC, 0666);
      execlp("who", "who", (char *)NULL);
    } else {
      wait();
      if (!fork()) {
        close(1);
        open("fres", O_WRONLY | O_CREAT | O_TRUNC, 0666);
        execlp("grep", "grep", argv[1], "ftemp", (char *)NULL);
      } else {
        wait();
        int fd = open("fres", O_RDONLY);
        char buf[10];
        if (read(fd, buf, 10) > 0)
          printf("Yes");
        else
          printf("No");
      }
    }
  } else {
    printf("No username provided");
  }
  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)
cmpl   $0x1,-0x8(%rbp)
jle    12d3 <main+0x163>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11f2 <main+0x82>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2e3e(%rip),%rax
or     (%rax),%esi
mov    0x2e2d(%rip),%rax
or     (%rax),%esi
lea    0xe34(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
lea    0xe27(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execlp@plt>
jmp    12ce <main+0x15e>
mov    $0x0,%al
call   1080 <wait@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    126b <main+0xfb>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
mov    0x2dc4(%rip),%rax
or     (%rax),%esi
lea    0xdd5(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdbf(%rip),%rsi
lea    0xda9(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execlp@plt>
jmp    12c9 <main+0x159>
mov    $0x0,%al
call   1080 <wait@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    12b8 <main+0x148>
lea    0xd66(%rip),%rdi
call   1030 <printf@plt>
jmp    12c4 <main+0x154>
lea    0xd59(%rip),%rdi
call   1030 <printf@plt>
jmp    12c9 <main+0x159>
jmp    12ce <main+0x15e>
jmp    12df <main+0x16f>
lea    0xd41(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     11e4 <main+0x74>
mov    %rsi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11f5 <main+0x85>
xor    %eax,%eax
call   1080 <wait@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1242 <main+0xd2>
xor    %eax,%eax
call   1080 <wait@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %rax,%rax
lea    0xe3d(%rip),%rax
lea    0xe3a(%rip),%rdi
cmovg  %rax,%rdi
jmp    11eb <main+0x7b>
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
jmp    1299 <main+0x129>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2dba(%rip),%rax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
lea    0xddf(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
lea    0xdd2(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execlp@plt>
jmp    1299 <main+0x129>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2d6d(%rip),%rax
mov    0x2d9e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d8b(%rip),%rax
or     (%rax),%esi
lea    0xd9c(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    0x8(%rbx),%rdx
lea    0xd8a(%rip),%rdi
lea    0xd74(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
xor    %eax,%eax
call   1070 <execlp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ftemp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [4 x i8] c"who\00"
@.str.2 = [5 x i8] c"fres\00"
@.str.3 = [5 x i8] c"grep\00"
@O_RDONLY = global i32 0
@.str.4 = [4 x i8] c"Yes\00"
@.str.5 = [3 x i8] c"No\00"
@.str.6 = [21 x i8] c"No username provided\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %53
10: ; preds = %2
%11 = call i32 (...) @fork()
%12 = icmp ne i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %10
%14 = call i32 @close(i32 1)
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19, i32 438)
%21 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %52
22: ; preds = %10
%23 = call i32 (...) @wait()
%24 = call i32 (...) @fork()
%25 = icmp ne i32 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %22
%27 = call i32 @close(i32 1)
%28 = load i32, i32* @O_WRONLY
%29 = load i32, i32* @O_CREAT
%30 = or i32 %28, %29
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 438)
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %51
38: ; preds = %22
%39 = call i32 (...) @wait()
%40 = load i32, i32* @O_RDONLY
%41 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%44 = call i64 @read(i32 %42, i8* %43, i32 10)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %50
48: ; preds = %38
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
br label %51
51: ; preds = %50, %26
br label %52
52: ; preds = %51, %13
br label %55
53: ; preds = %2
%54 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %53, %52
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"ftemp\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [4 x i8] c"who\00"
@.str.2 = [5 x i8] c"fres\00"
@.str.3 = [5 x i8] c"grep\00"
@O_RDONLY = global i32 0
@.str.4 = [4 x i8] c"Yes\00"
@.str.5 = [3 x i8] c"No\00"
@.str.6 = [21 x i8] c"No username provided\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %41
5: ; preds = %2
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = tail call i32 @close(i32 1)
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %11, %10
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14, i32 438)
%16 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* null)
br label %43
17: ; preds = %5
%18 = tail call i32 (...) @wait()
%19 = tail call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = tail call i32 @close(i32 1)
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_CREAT
%25 = or i32 %24, %23
%26 = load i32, i32* @O_TRUNC
%27 = or i32 %25, %26
%28 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 438)
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %43
32: ; preds = %17
%33 = tail call i32 (...) @wait()
%34 = load i32, i32* @O_RDONLY
%35 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%37 = call i64 @read(i32 %35, i8* %36, i32 10)
%38 = icmp sgt i64 %37, 0
%39 = select i1 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%40 = tail call i32 @printf(i8* dereferenceable(1) %39)
br label %43
41: ; preds = %2
%42 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %8, %32, %21, %41
ret i32 0
}