#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 atoi(char *);
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 argc, char **argv) {
  int nprocs = atoi(argv[1]);
  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 < nprocs; ++i) {
    if (fork() == 0) {
      poll(input_pins[i]);
      exit(0);
    }
  }
  int child = 0;
  for (child = 0; child < nprocs; ++child) {
    wait(NULL);
  }
  for (i = 0; i < nprocs; ++i) {
    close(input_pins[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xe64(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x30(%rbp)
lea    0xe54(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x2c(%rbp)
lea    0xe49(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x28(%rbp)
lea    0xe3d(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1224 <main+0xb4>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1211 <main+0xa1>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1050 <poll@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    1216 <main+0xa6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e0 <main+0x70>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1255 <main+0xe5>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1232 <main+0xc2>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1283 <main+0x113>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1030 <close@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    125c <main+0xec>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
lea    0xe74(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,%r14d
mov    %eax,(%rsp)
lea    0xe61(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,0x4(%rsp)
lea    0xe55(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,0x8(%rsp)
lea    0xe48(%rip),%rdi
call   1040 <pin_read@plt>
mov    %eax,0xc(%rsp)
test   %r15d,%r15d
jle    1241 <main+0xd1>
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     124e <main+0xde>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    11e0 <main+0x70>
test   %r15d,%r15d
jle    1241 <main+0xd1>
mov    %r15d,%ebx
nopl   0x0(%rax)
xor    %edi,%edi
call   1080 <wait@plt>
add    $0xffffffff,%ebx
jne    1200 <main+0x90>
test   %r15d,%r15d
jle    1241 <main+0xd1>
mov    %r14d,%edi
call   1030 <close@plt>
cmp    $0x1,%ebp
je     1241 <main+0xd1>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp,%rbx,4),%edi
call   1030 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1230 <main+0xc0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp,%rbx,4),%edi
call   1050 <poll@plt>
xor    %edi,%edi
call   1070 <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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4 x i32]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %6
%14 = call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
store i32 %14, i32* %15
%16 = call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 1
store i32 %16, i32* %17
%18 = call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 2
store i32 %18, i32* %19
%20 = call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 3
store i32 %20, i32* %21
store i32 0, i32* %8
store i32 0, i32* %8
br label %22
22: ; preds = %37, %2
%23 = load i32, i32* %8
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %40
26: ; preds = %22
%27 = call i64 (...) @fork()
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @poll(i32 %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %26
br label %37
37: ; preds = %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %22
40: ; preds = %22
store i32 0, i32* %9
store i32 0, i32* %9
br label %41
41: ; preds = %47, %40
%42 = load i32, i32* %9
%43 = load i32, i32* %6
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = call i32 @wait(i32* null)
br label %47
47: ; preds = %45
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %41
50: ; preds = %41
store i32 0, i32* %8
br label %51
51: ; preds = %61, %50
%52 = load i32, i32* %8
%53 = load i32, i32* %6
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %51
64: ; preds = %51
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(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i32]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = bitcast [4 x i32]* %3 to i8*
%8 = tail call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
store i32 %8, i32* %9
%10 = tail call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
store i32 %10, i32* %11
%12 = tail call i32 @pin_read(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
store i32 %12, i32* %13
%14 = tail call i32 @pin_read(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
store i32 %14, i32* %15
%16 = icmp sgt i32 %6, 0
br i1 %16, label %18, label %48
17: ; preds = %28
br i1 %16, label %36, label %48
18: ; preds = %2, %28
%19 = phi i32 [ %29, %28 ], [ 0, %2 ]
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = zext i32 %19 to i64
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = tail call i32 @poll(i32 %25)
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %18
%29 = add nuw nsw i32 %19, 1
%30 = icmp eq i32 %29, %6
br i1 %30, label %17, label %18
31: ; preds = %36
br i1 %16, label %32, label %48
32: ; preds = %31
%33 = zext i32 %6 to i64
%34 = tail call i32 @close(i32 %8)
%35 = icmp eq i32 %6, 1
br i1 %35, label %48, label %41
36: ; preds = %17, %36
%37 = phi i32 [ %39, %36 ], [ 0, %17 ]
%38 = tail call i32 @wait(i32* null)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, %6
br i1 %40, label %31, label %36
41: ; preds = %32, %41
%42 = phi i64 [ %46, %41 ], [ 1, %32 ]
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = tail call i32 @close(i32 %44)
%46 = add nuw nsw i64 %42, 1
%47 = icmp eq i64 %46, %33
br i1 %47, label %48, label %41
48: ; preds = %41, %32, %2, %17, %31
ret i32 0
}