#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*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execl(char *, char *, char *);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char input1[255];
  char input2[255];
  int fds[2];
  int pid;
  do {
    scanf("%s", input1);
    if (!strcmp(input1, "service"))
      break;
    else
      printf("Error: Input error\n");
  } while (1);
  scanf("%s", input2);
  pipe(fds);
  pid = fork();
  if (pid == 0) {
    close(fds[1]);
    close(0);
    dup(fds[0]);
    execl("./runlevel.sh", "runlevel.sh", (char *)NULL);
  } else if (pid > 0) {
    close(fds[0]);
    close(1);
    dup(fds[1]);
    printf("%s", input2);
  } else {
    printf("Error: fork()\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11cd <main+0x4d>
jmp    11ef <main+0x6f>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e0 <main+0x60>
mov    $0x1,%al
test   $0x1,%al
jne    1199 <main+0x19>
jmp    11ef <main+0x6f>
lea    -0x210(%rbp),%rsi
lea    0xe03(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x218(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jne    1261 <main+0xe1>
mov    -0x214(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    -0x218(%rbp),%edi
call   1040 <dup@plt>
lea    0xdd3(%rip),%rdi
lea    0xdce(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <execl@plt>
jmp    12bb <main+0x13b>
cmpl   $0x0,-0x21c(%rbp)
jle    12a8 <main+0x128>
mov    -0x218(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0x214(%rbp),%edi
call   1040 <dup@plt>
lea    -0x210(%rbp),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b6 <main+0x136>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bb <main+0x13b>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x218,%rsp
movabs $0x65636976726573,%r12
lea    0xe61(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <scanf@plt>
cmp    %r12,0x10(%rsp)
je     11ea <main+0x6a>
lea    0xe68(%rip),%r14
lea    0xe42(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
cmp    %r12,0x10(%rsp)
jne    11d0 <main+0x50>
lea    0xe0f(%rip),%rdi
lea    0x110(%rsp),%rsi
call   1080 <scanf@plt>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1249 <main+0xc9>
jle    1279 <main+0xf9>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <dup@plt>
lea    0xdc8(%rip),%rdi
lea    0x110(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1285 <main+0x105>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <dup@plt>
lea    0xd9a(%rip),%rdi
lea    0xd95(%rip),%rsi
xor    %edx,%edx
call   1090 <execl@plt>
jmp    1285 <main+0x105>
lea    0xd91(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"service\00"
@.str.2 = [20 x i8] c"Error: Input error\0A\00"
@.str.3 = [14 x i8] c"./runlevel.sh\00"
@.str.4 = [12 x i8] c"runlevel.sh\00"
@.str.5 = [15 x i8] c"Error: fork()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
%7 = alloca [255 x i8]
%8 = alloca [2 x i32]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %20, %2
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %10
br label %21
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17
br label %20
20: ; preds = %19
br i1 true, label %10, label %21
21: ; preds = %20, %16
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%25 = call i32 @pipe(i32* %24)
%26 = call i32 (...) @fork()
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %21
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = call i32 @close(i32 0)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @dup(i32 %35)
%37 = call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %54
38: ; preds = %21
%39 = load i32, i32* %9
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
%45 = call i32 @close(i32 1)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @dup(i32 %47)
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %53
51: ; preds = %38
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %41
br label %54
54: ; preds = %53, %29
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.3 = [14 x i8] c"./runlevel.sh\00"
@.str.4 = [12 x i8] c"runlevel.sh\00"
@str = [14 x i8] c"Error: fork()\00"
@str.6 = [19 x i8] c"Error: Input error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca [2 x i32]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = bitcast [2 x i32]* %5 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%10 = bitcast [255 x i8]* %3 to i64*
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 28538277257700723
br i1 %12, label %18, label %13
13: ; preds = %2, %13
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%16 = load i64, i64* %10
%17 = icmp eq i64 %16, 28538277257700723
br i1 %17, label %18, label %13
18: ; preds = %13, %2
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%21 = call i32 @pipe(i32* %20)
%22 = call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = call i32 @close(i32 0)
%29 = load i32, i32* %20
%30 = call i32 @dup(i32 %29)
%31 = call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* null)
br label %44
32: ; preds = %18
%33 = icmp sgt i32 %22, 0
br i1 %33, label %34, label %42
34: ; preds = %32
%35 = load i32, i32* %20
%36 = call i32 @close(i32 %35)
%37 = call i32 @close(i32 1)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @dup(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %44
42: ; preds = %32
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %34, %42, %24
ret i32 0
}