#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 fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait();
int main(void) {
  int pid, y;
  char cmd[20];
  pid = fork();
  do {
    if (pid == 0) {
      printf("\nChild Process:\n");
      printf("Enter the command: ");
      scanf("%s", cmd);
      system(cmd);
      printf("\nEnter 0 to exit or 1 to continue: ");
      scanf("%d", &y);
    } else {
      wait();
    }
  } while (y == 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11c9 <main+0x79>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <system@plt>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
jmp    11d0 <main+0x80>
mov    $0x0,%al
call   1060 <wait@plt>
jmp    11d5 <main+0x85>
cmpl   $0x1,-0xc(%rbp)
je     1169 <main+0x19>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebx
lea    0xe96(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xe8d(%rip),%rbp
lea    0xeaa(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11ae <main+0x4e>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <wait@plt>
cmpl   $0x1,0xc(%rsp)
jne    11fb <main+0x9b>
test   %ebx,%ebx
jne    11a0 <main+0x40>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r13,%rdi
call   1040 <system@plt>
mov    %rbp,%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x1,0xc(%rsp)
je     11ae <main+0x4e>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0AChild Process:\0A\00"
@.str.1 = [20 x i8] c"Enter the command: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [36 x i8] c"\0AEnter 0 to exit or 1 to continue: \00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
br label %6
6: ; preds = %21, %0
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%15 = call i32 @system(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
br label %20
18: ; preds = %6
%19 = call i32 (...) @wait()
br label %20
20: ; preds = %18, %9
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 1
br i1 %23, label %6, label %24
24: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Enter the command: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [36 x i8] c"\0AEnter 0 to exit or 1 to continue: \00"
@.str.4 = [3 x i8] c"%d\00"
@str = [16 x i8] c"\0AChild Process:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br label %7
7: ; preds = %17, %0
br i1 %6, label %8, label %15
8: ; preds = %7
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32 @system(i8* %4)
%13 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %17
15: ; preds = %7
%16 = call i32 (...) @wait()
br label %17
17: ; preds = %8, %15
%18 = load i32, i32* %1
%19 = icmp eq i32 %18, 1
br i1 %19, label %7, label %20
20: ; preds = %17
ret i32 0
}