#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*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int pin_read(char *);
int /*<<< orphan*/ poll(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int input_pins[4];
  input_pins[0] = pin_read("91");
  input_pins[1] = pin_read("191");
  input_pins[2] = pin_read("24");
  input_pins[3] = pin_read("200");
  int i = 0;
  for (i = 0; i < 4; ++i) {
    if (fork() == 0) {
      poll(input_pins[i]);
      exit(0);
    }
  }
  int child = 0;
  for (child = 0; child < 4; ++child) {
    wait(NULL);
  }
  for (i = 0; i < 4; ++i) {
    close(input_pins[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8b(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x20(%rbp)
lea    0xe7b(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe70(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x18(%rbp)
lea    0xe64(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11fb <main+0x9b>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11e8 <main+0x88>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
call   1050 <poll@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    11ed <main+0x8d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b9 <main+0x59>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    122a <main+0xca>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1209 <main+0xa9>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1256 <main+0xf6>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
call   1030 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1231 <main+0xd1>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8e(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,%r14d
mov    %eax,(%rsp)
lea    0xe7b(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,%r15d
mov    %eax,0x4(%rsp)
lea    0xe6c(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,%ebx
mov    %eax,0x8(%rsp)
lea    0xe5d(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,%ebp
mov    %eax,0xc(%rsp)
xor    %r12d,%r12d
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     124b <main+0xeb>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1235 <main+0xd5>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     123d <main+0xdd>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1245 <main+0xe5>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
mov    %r14d,%edi
call   1030 <close@plt>
mov    %r15d,%edi
call   1030 <close@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
jmp    124b <main+0xeb>
mov    $0x2,%r12d
jmp    124b <main+0xeb>
mov    $0x3,%r12d
mov    (%rsp,%r12,4),%edi
call   1050 <poll@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"91\00"
@.str.1 = [4 x i8] c"191\00"
@.str.2 = [3 x i8] c"24\00"
@.str.3 = [4 x i8] c"200\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 %5, i32* %6
%7 = call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
store i32 %7, i32* %8
%9 = call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
store i32 %9, i32* %10
%11 = call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
store i32 %11, i32* %12
store i32 0, i32* %3
store i32 0, i32* %3
br label %13
13: ; preds = %27, %0
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 4
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @poll(i32 %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %13
30: ; preds = %13
store i32 0, i32* %4
store i32 0, i32* %4
br label %31
31: ; preds = %36, %30
%32 = load i32, i32* %4
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = call i32 @wait(i32* null)
br label %36
36: ; preds = %34
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %31
39: ; preds = %31
store i32 0, i32* %3
br label %40
40: ; preds = %49, %39
%41 = load i32, i32* %3
%42 = icmp slt i32 %41, 4
br i1 %42, label %43, label %52
43: ; preds = %40
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %43
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %40
52: ; preds = %40
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"91\00"
@.str.1 = [4 x i8] c"191\00"
@.str.2 = [3 x i8] c"24\00"
@.str.3 = [4 x i8] c"200\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = tail call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
store i32 %3, i32* %4
%5 = tail call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
store i32 %5, i32* %6
%7 = tail call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
store i32 %7, i32* %8
%9 = tail call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 3
store i32 %9, i32* %10
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %25, %22, %19, %0
%14 = phi i64 [ 0, %0 ], [ 1, %19 ], [ 2, %22 ], [ 3, %25 ]
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @poll(i32 %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %13, label %22
22: ; preds = %19
%23 = tail call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %22
%26 = tail call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %13, label %28
28: ; preds = %25
%29 = tail call i32 @wait(i32* null)
%30 = tail call i32 @wait(i32* null)
%31 = tail call i32 @wait(i32* null)
%32 = tail call i32 @wait(i32* null)
%33 = tail call i32 @close(i32 %3)
%34 = tail call i32 @close(i32 %5)
%35 = tail call i32 @close(i32 %7)
%36 = tail call i32 @close(i32 %9)
ret i32 0
}