#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*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int getpid();
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *, char *, ...);
int read(int, int *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("Usage: %s <pipe> [number].\n", argv[0]);
    return (-1);
  }
  int pid = getpid();
  printf("%s process [%d]: starting.\n", argv[0], pid);
  int str_size = strlen(argv[2]);
  for (int o = 0; o < str_size; ++o) {
    if (!(isdigit(argv[2][o]))) {
      fprintf(stderr, "%s process [%d]: %s is not a valid input.\n", argv[0],
              pid, argv[2]);
      return (2);
    }
  }
  int pipefd = atoi(argv[1]), nbytes;
  int buf = -1;
  while (buf == -1) {
    nbytes = read(pipefd, &buf, sizeof(int));
  }
  printf("%s process [%d]: read %d bytes containing value: %d\n", argv[0], pid,
         nbytes, buf);
  int one = atoi(argv[2]);
  int result = ((one * buf) & 1);
  if (result) {
    printf("%s process [%d]: %d *IS* even.\n", argv[0], pid, one * buf);
  } else {
    printf("%s process [%d]: %d *IS NOT* even.\n", argv[0], pid, one * buf);
  }
  printf("%s: exiting.\n", argv[0]);
  return (result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1338 <main+0x1c8>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    125a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1247 <main+0xd7>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xe02(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1338 <main+0x1c8>
jmp    124c <main+0xdc>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ea <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1294 <main+0x124>
mov    -0x20(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
jmp    1271 <main+0x101>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x28(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     12fe <main+0x18e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
imul   -0x28(%rbp),%ecx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    131d <main+0x1ad>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
imul   -0x28(%rbp),%ecx
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%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
mov    %rsi,%r12
cmp    $0x3,%edi
jne    127c <main+0x10c>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r14d
mov    (%r12),%rsi
lea    0xe7f(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r12),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11df <main+0x6f>
mov    %eax,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x10(%r12),%rax
movsbl (%rax,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1296 <main+0x126>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <main+0x50>
mov    0x8(%r12),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0xc(%rsp),%ebp
cmp    $0xffffffff,%ebp
je     1200 <main+0x90>
mov    (%r12),%rsi
lea    0xe40(%rip),%rdi
mov    %r14d,%edx
mov    %eax,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r12),%rdi
call   1090 <atoi@plt>
imul   %eax,%ebp
mov    %ebp,%r15d
and    $0x1,%r15d
mov    (%r12),%rsi
lea    0xe67(%rip),%rax
lea    0xe40(%rip),%rdi
cmove  %rax,%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%rsi
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12bd <main+0x14d>
mov    (%r12),%rsi
lea    0xd79(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%r15d
jmp    12bd <main+0x14d>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
mov    0x10(%r12),%r8
lea    0xd89(%rip),%rsi
mov    %r14d,%ecx
call   1080 <fprintf@plt>
mov    $0x2,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: %s <pipe> [number].\0A\00"
@.str.1 = [28 x i8] c"%s process [%d]: starting.\0A\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"%s process [%d]: %s is not a valid input.\0A\00"
@.str.3 = [53 x i8] c"%s process [%d]: read %d bytes containing value: %d\0A\00"
@.str.4 = [32 x i8] c"%s process [%d]: %d *IS* even.\0A\00"
@.str.5 = [36 x i8] c"%s process [%d]: %d *IS NOT* even.\0A\00"
@.str.6 = [14 x i8] c"%s: exiting.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %113
21: ; preds = %2
%22 = call i32 (...) @getpid()
store i32 %22, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i32, i32* %6
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %7
store i32 0, i32* %8
br label %32
32: ; preds = %57, %21
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %60
36: ; preds = %32
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = call i32 @isdigit(i8 signext %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %36
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i32, i32* %6
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %50, i32 %51, i8* %54)
store i32 2, i32* %3
br label %113
56: ; preds = %36
br label %57
57: ; preds = %56
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %32
60: ; preds = %32
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i32 @atoi(i8* %63)
store i32 %64, i32* %9
store i32 -1, i32* %11
br label %65
65: ; preds = %68, %60
%66 = load i32, i32* %11
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %9
%70 = call i32 @read(i32 %69, i32* %11, i32 4)
store i32 %70, i32* %10
br label %65
71: ; preds = %65
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 0
%74 = load i8*, i8** %73
%75 = load i32, i32* %6
%76 = load i32, i32* %10
%77 = load i32, i32* %11
%78 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %74, i32 %75, i32 %76, i32 %77)
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 2
%81 = load i8*, i8** %80
%82 = call i32 @atoi(i8* %81)
store i32 %82, i32* %12
%83 = load i32, i32* %12
%84 = load i32, i32* %11
%85 = mul nsw i32 %83, %84
%86 = and i32 %85, 1
store i32 %86, i32* %13
%87 = load i32, i32* %13
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %98
89: ; preds = %71
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 0
%92 = load i8*, i8** %91
%93 = load i32, i32* %6
%94 = load i32, i32* %12
%95 = load i32, i32* %11
%96 = mul nsw i32 %94, %95
%97 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %92, i32 %93, i32 %96)
br label %107
98: ; preds = %71
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 0
%101 = load i8*, i8** %100
%102 = load i32, i32* %6
%103 = load i32, i32* %12
%104 = load i32, i32* %11
%105 = mul nsw i32 %103, %104
%106 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %101, i32 %102, i32 %105)
br label %107
107: ; preds = %98, %89
%108 = load i8**, i8*** %5
%109 = getelementptr inbounds i8*, i8** %108, i64 0
%110 = load i8*, i8** %109
%111 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %110)
%112 = load i32, i32* %13
store i32 %112, i32* %3
br label %113
113: ; preds = %107, %46, %16
%114 = load i32, i32* %3
ret i32 %114
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: %s <pipe> [number].\0A\00"
@.str.1 = [28 x i8] c"%s process [%d]: starting.\0A\00"
@stderr = global i32 0
@.str.2 = [43 x i8] c"%s process [%d]: %s is not a valid input.\0A\00"
@.str.3 = [53 x i8] c"%s process [%d]: read %d bytes containing value: %d\0A\00"
@.str.4 = [32 x i8] c"%s process [%d]: %d *IS* even.\0A\00"
@.str.5 = [36 x i8] c"%s process [%d]: %d *IS NOT* even.\0A\00"
@.str.6 = [14 x i8] c"%s: exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %55
8: ; preds = %2
%9 = tail call i32 (...) @getpid()
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %9)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %8
%17 = zext i32 %14 to i64
br label %20
18: ; preds = %20
%19 = icmp eq i64 %27, %17
br i1 %19, label %33, label %20
20: ; preds = %16, %18
%21 = phi i64 [ 0, %16 ], [ %27, %18 ]
%22 = load i8*, i8** %12
%23 = getelementptr inbounds i8, i8* %22, i64 %21
%24 = load i8, i8* %23
%25 = tail call i32 @isdigit(i8 signext %24)
%26 = icmp eq i32 %25, 0
%27 = add nuw nsw i64 %21, 1
br i1 %26, label %28, label %18
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %1
%31 = load i8*, i8** %12
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 %9, i8* %31)
br label %55
33: ; preds = %18, %8
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i32 @atoi(i8* %35)
%37 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
br label %38
38: ; preds = %33, %38
%39 = call i32 @read(i32 %36, i32* %3, i32 4)
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, -1
br i1 %41, label %38, label %42
42: ; preds = %38
%43 = load i8*, i8** %1
%44 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %9, i32 %39, i32 %40)
%45 = load i8*, i8** %12
%46 = tail call i32 @atoi(i8* %45)
%47 = mul nsw i32 %46, %40
%48 = and i32 %47, 1
%49 = icmp eq i32 %48, 0
%50 = load i8*, i8** %1
%51 = select i1 %49, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0)
%52 = tail call i32 (i8*, i8*, ...) @printf(i8* %51, i8* %50, i32 %9, i32 %47)
%53 = load i8*, i8** %1
%54 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %28, %42, %5
%56 = phi i32 [ -1, %5 ], [ %48, %42 ], [ 2, %28 ]
ret i32 %56
}