#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 *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/, char *, char *);
int getpid();
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
main() {
  pid_t k;
  char buf[100];
  int status;
  int len;
  while (1) {
    fprintf(stdout, "[%d]$ ", getpid());
    fscanf(stdin, "%s", buf);
    k = fork();
    if (k == 0) {
      execlp(buf, buf, NULL);
    } else {
      waitpid(k, &status, 0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x8c(%rbp),%edi
mov    %eax,%edx
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xe57(%rip),%rsi
call   1040 <fscanf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <main+0x81>
lea    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
jmp    11f3 <main+0x93>
mov    -0x10(%rbp),%rdi
lea    -0x84(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    1172 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e63(%rip),%r13
lea    0xe84(%rip),%r14
mov    0x2e65(%rip),%r12
lea    0xe7d(%rip),%r15
lea    0x10(%rsp),%rbx
jmp    11af <main+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0x0(%r13),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    (%r12),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11a0 <main+0x40>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
jmp    11af <main+0x4f>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"[%d]$ \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %0, %23
%7 = load i32, i32* @stdout
%8 = call i32 (...) @getpid()
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stdin
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 @fscanf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i64 (...) @fork()
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %6
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i32 @execlp(i8* %17, i8* %18, i32* null)
br label %23
20: ; preds = %6
%21 = load i64, i64* %2
%22 = call i32 @waitpid(i64 %21, i32* %4, i32 0)
br label %23
23: ; preds = %20, %16
br label %6
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"[%d]$ \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* @stdout
%7 = call i32 (...) @getpid()
%8 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @stdin
%10 = call i32 @fscanf(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = call i32 @execlp(i8* %3, i8* %3, i32* null)
br label %17
15: ; preds = %5
%16 = call i32 @waitpid(i64 %11, i32* %2, i32 0)
br label %17
17: ; preds = %15, %13
br label %5
}