#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int main(void) {
  pid_t pid;
  char buf[20];
  printf("Enter input (n = next, other input terminates):");
  fgets(buf, 20, stdin);
  while (buf[0] == 'n') {
    pid = fork();
    if (pid < 0) {
      perror("Fork:");
      exit(1);
    }
    if (pid == 0) {
      sleep(5);
      exit(0);
    }
    printf("Enter input (n = next, other input terminates):");
    fgets(buf, 20, stdin);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fgets@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x6e,%eax
jne    120f <main+0xaf>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11cb <main+0x6b>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11e7 <main+0x87>
mov    $0x5,%edi
call   1070 <sleep@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fgets@plt>
jmp    1192 <main+0x32>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6c(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
cmpb   $0x6e,(%rsp)
jne    11cc <main+0x6c>
lea    0xe67(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11d8 <main+0x78>
je     11ee <main+0x8e>
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1040 <fgets@plt>
cmpb   $0x6e,(%rsp)
je     11a0 <main+0x40>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x5,%edi
call   1070 <sleep@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Enter input (n = next, other input terminates):\00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"Fork:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [20 x i8]
store i32 0, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 20, i32 %6)
br label %8
8: ; preds = %26, %0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 110
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = call i64 (...) @fork()
store i64 %14, i64* %2
%15 = load i64, i64* %2
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = load i64, i64* %2
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @sleep(i32 5)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %20
%27 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %28, i32 20, i32 %29)
br label %8
31: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [48 x i8] c"Enter input (n = next, other input terminates):\00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"Fork:\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 20, i32 %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 110
br i1 %7, label %8, label %25
8: ; preds = %0, %19
%9 = call i64 (...) @fork()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = icmp eq i64 %9, 0
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = call i32 @sleep(i32 5)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %14
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %2, i32 20, i32 %21)
%23 = load i8, i8* %2
%24 = icmp eq i8 %23, 110
br i1 %24, label %8, label %25
25: ; preds = %19, %0
ret i32 0
}