#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 /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char **);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  while (1) {
    printf("%s", "\n$ ");
    char *buf;
    scanf("%ms", &buf);
    if (!fork())
      execlp(buf, buf, (char *)NULL);
    else
      wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
jne    11a8 <main+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
jmp    11b1 <main+0x61>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
jmp    115f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%r14
lea    0xe9d(%rip),%r15
lea    0xe9a(%rip),%r12
mov    %rsp,%rbx
jmp    118e <main+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1050 <execlp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1180 <main+0x30>
xor    %edi,%edi
call   1060 <wait@plt>
jmp    118e <main+0x3e>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"\0A$ \00"
@.str.2 = [4 x i8] c"%ms\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
br label %3
3: ; preds = %0, %14
%4 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %2)
%6 = call i32 (...) @fork()
%7 = icmp ne i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @execlp(i8* %9, i8* %10, i8* null)
br label %14
12: ; preds = %3
%13 = call i32 @wait(i32* null)
br label %14
14: ; preds = %12, %8
br label %3
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"\0A$ \00"
@.str.2 = [4 x i8] c"%ms\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
br label %3
3: ; preds = %0, %13
%4 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %1)
%6 = call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i8*, i8** %1
%10 = call i32 @execlp(i8* %9, i8* %9, i8* null)
br label %13
11: ; preds = %3
%12 = call i32 @wait(i32* null)
br label %13
13: ; preds = %11, %8
br label %3
}