#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 BUFSIZ;
int EXIT_SUCCESS;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int pid = fork();
  if (pid == 0) {
    argv++;
    execvp(*argv, argv);
  } else {
    wait(NULL);
    char buf[BUFSIZ];
    while (fgets(buf, BUFSIZ, stdin) != NULL)
      printf("%s\n", buf);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119b <main+0x4b>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execvp@plt>
jmp    1211 <main+0xc1>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
mov    -0x30(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
jmp    11d0 <main+0x80>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11e5 <main+0x95>
xor    %edi,%edi
call   1060 <wait@plt>
mov    %rsp,%r15
mov    0x2e5b(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%r12),%esi
mov    0x2e4b(%rip),%r13
mov    0x0(%r13),%edx
mov    %rbx,%rdi
call   1040 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x90>
lea    0xe4b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r12),%esi
mov    0x0(%r13),%edx
mov    %rbx,%rdi
call   1040 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x70>
mov    %r15,%rsp
jmp    11f5 <main+0xa5>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1050 <execvp@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = call i32 @execvp(i8* %16, i8** %17)
br label %34
19: ; preds = %2
%20 = call i32 @wait(i32* null)
%21 = load i32, i32* @BUFSIZ
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %7
%24 = alloca i8, i64 %22
store i64 %22, i64* %8
br label %25
25: ; preds = %30, %19
%26 = load i32, i32* @BUFSIZ
%27 = load i32, i32* @stdin
%28 = call i32* @fgets(i8* %24, i32 %26, i32 %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %25
32: ; preds = %25
%33 = load i8*, i8** %7
br label %34
34: ; preds = %32, %12
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @execvp(i8* %7, i8** %6)
br label %26
9: ; preds = %2
%10 = tail call i32 @wait(i32* null)
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = load i32, i32* @BUFSIZ
%16 = load i32, i32* @stdin
%17 = call i32* @fgets(i8* %14, i32 %15, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %25, label %19
19: ; preds = %9, %19
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
%21 = load i32, i32* @BUFSIZ
%22 = load i32, i32* @stdin
%23 = call i32* @fgets(i8* %14, i32 %21, i32 %22)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %19
25: ; preds = %19, %9
br label %26
26: ; preds = %25, %5
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}