#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;
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
char *getenv(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  while (1) {
    char hostname[20] = " ";
    printf("[%s@", getenv("USER"));
    gethostname(hostname, sizeof(hostname));
    printf("%s:", hostname);
    printf("%s]$", getenv("PWD"));
    fflush(stdout);
    char cmd_strtok[100] = " ";
    pid_t pid;
    pid = fork();
    if (pid < 0) {
      perror("fork");
    }
    if (pid == 0) {
      scanf("%[^\n]", cmd_strtok);
      char *cmd[10] = {NULL};
      int i = 0;
      cmd[0] = strtok(cmd_strtok, " ");
      while (cmd[i] != NULL) {
        cmd[++i] = strtok(NULL, " ");
      }
      execvp(cmd[0], cmd);
      perror("execvp");
      exit(0);
    } else {
      sleep(1);
      wait(NULL);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe10(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe0d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe0b(%rip),%eax
mov    %eax,-0x20(%rbp)
lea    0xe0a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
call   10b0 <gethostname@plt>
lea    -0x30(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
movb   $0x20,-0xa0(%rbp)
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jge    12ac <main+0xdc>
lea    0xd84(%rip),%rdi
call   1080 <perror@plt>
cmpq   $0x0,-0xa8(%rbp)
jne    1371 <main+0x1a1>
lea    -0xa0(%rbp),%rsi
lea    0xd68(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
movl   $0x0,-0x104(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x100(%rbp)
movslq -0x104(%rbp),%rax
cmpq   $0x0,-0x100(%rbp,%rax,8)
je     134b <main+0x17b>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd11(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,%rcx
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
cltq
mov    %rcx,-0x100(%rbp,%rax,8)
ff
jmp    1304 <main+0x134>
mov    -0x100(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   10a0 <execvp@plt>
lea    0xcd3(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
jmp    11e9 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xe3c(%rip),%r15
mov    %rsp,%rbx
lea    0xe3c(%rip),%r12
lea    0xe3e(%rip),%r13
lea    0xe32(%rip),%rbp
mov    0x2de9(%rip),%r14
jmp    1221 <main+0x61>
lea    0xe2b(%rip),%rdi
call   1070 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   10c0 <sleep@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
movaps 0xdd8(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xdde(%rip),%rdi
call   1030 <getenv@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   10a0 <gethostname@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <getenv@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%r14),%edi
call   1050 <fflush@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movl   $0x0,0xd0(%rsp)
movb   $0x20,0x70(%rsp)
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     11f9 <main+0x39>
jne    1210 <main+0x50>
lea    0xd55(%rip),%rdi
lea    0x70(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xd2b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strtok@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
jne    1321 <main+0x161>
xor    %edi,%edi
jmp    134c <main+0x18c>
lea    0x28(%rsp),%rbp
lea    0xd09(%rip),%rbx
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
mov    %rax,0x0(%rbp)
add    $0x8,%rbp
test   %rax,%rax
jne    1330 <main+0x170>
mov    0x20(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1090 <execvp@plt>
lea    0xcdb(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.hostname = [20 x i8] c" \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"[%s@\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [4 x i8] c"%s:\00"
@.str.3 = [5 x i8] c"%s]$\00"
@.str.4 = [4 x i8] c"PWD\00"
@stdout = global i32 0
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [6 x i8] c"%[^\0A]\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca [100 x i8]
%8 = alloca i64
%9 = alloca [10 x i8*]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %11
11: ; preds = %2, %63
%12 = bitcast [20 x i8]* %6 to i8*
%13 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%16 = call i32 @gethostname(i8* %15, i32 20)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = bitcast [100 x i8]* %7 to i8*
%24 = bitcast i8* %23 to [100 x i8]*
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %24, i32 0, i32 0
store i8 32, i8* %25
%26 = call i64 (...) @fork()
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %11
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %11
%32 = load i64, i64* %8
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %60
34: ; preds = %31
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%36 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %35)
%37 = bitcast [10 x i8*]* %9 to i8*
store i32 0, i32* %10
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%39 = call i8* @strtok(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%40 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
store i8* %39, i8** %40
br label %41
41: ; preds = %47, %34
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %51
store i8* %48, i8** %52
br label %41
53: ; preds = %41
%54 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%57 = call i32 @execvp(i8* %55, i8** %56)
%58 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %31
%61 = call i32 @sleep(i32 1)
%62 = call i32 @wait(i32* null)
br label %63
63: ; preds = %60
br label %11
}

LLVM IR (-O2):
@__const.main.hostname = [20 x i8] c" \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"[%s@\00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [4 x i8] c"%s:\00"
@.str.3 = [5 x i8] c"%s]$\00"
@.str.4 = [4 x i8] c"PWD\00"
@stdout = global i32 0
@.str.5 = [5 x i8] c"fork\00"
@.str.6 = [6 x i8] c"%[^\0A]\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = alloca [100 x i8]
%5 = alloca [10 x i8*]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
br label %8
8: ; preds = %2, %42
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32 @gethostname(i8* %6, i32 20)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
store i8 32, i8* %7
%17 = call i64 (...) @fork()
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %8
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %42
21: ; preds = %8
%22 = icmp eq i64 %17, 0
br i1 %22, label %23, label %42
23: ; preds = %21
%24 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%25 = bitcast [10 x i8*]* %5 to i8*
%26 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%27 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 0
store i8* %26, i8** %27
%28 = icmp eq i8* %26, null
br i1 %28, label %37, label %29
29: ; preds = %23, %29
%30 = phi i64 [ %32, %29 ], [ 0, %23 ]
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%32 = add nuw nsw i64 %30, 1
%33 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 %32
store i8* %31, i8** %33
%34 = icmp eq i8* %31, null
br i1 %34, label %35, label %29
35: ; preds = %29
%36 = load i8*, i8** %27
br label %37
37: ; preds = %35, %23
%38 = phi i8* [ %36, %35 ], [ null, %23 ]
%39 = call i32 @execvp(i8* %38, i8** %27)
%40 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %19, %21
%43 = call i32 @sleep(i32 1)
%44 = call i32 @wait(i32* null)
br label %8
}