#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 getpid();
scalar_t__ isPrime(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int write(int, int *, int);
int childHandle(int fd, int bottom, int top) {
  int i, size, ret = 0;
  int buf[2];
  printf("child %d: bottom=%d, top=%d\n", getpid(), bottom, top);
  buf[0] = getpid();
  for (i = bottom; i <= top; ++i) {
    if (isPrime(i)) {
      ++ret;
      buf[1] = i;
      if ((size = write(fd, buf, sizeof(int) * 2)) == -1) {
        perror("write");
      }
    }
  }
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<childHandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1211 <childHandle+0xb1>
mov    -0x10(%rbp),%edi
call   1070 <isPrime@plt>
cmp    $0x0,%rax
je     11fe <childHandle+0x9e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f9 <childHandle+0x99>
lea    0xe29(%rip),%rdi
call   1080 <perror@plt>
jmp    11fe <childHandle+0x9e>
jmp    1203 <childHandle+0xa3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a3 <childHandle+0x43>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<childHandle>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,(%rsp)
cmp    %r15d,%ebp
jle    11b7 <childHandle+0x57>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r15d
xor    %ebx,%ebx
mov    %rsp,%r12
lea    0xe56(%rip),%r13
jmp    11d8 <childHandle+0x78>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %ebp,%r15d
je     119e <childHandle+0x3e>
mov    %ebp,%edi
call   1070 <isPrime@plt>
test   %rax,%rax
je     11d0 <childHandle+0x70>
add    $0x1,%ebx
mov    %ebp,0x4(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11d0 <childHandle+0x70>
mov    %r13,%rdi
call   1080 <perror@plt>
jmp    11d0 <childHandle+0x70>

LLVM IR (-O0):
@.str = [29 x i8] c"child %d: bottom=%d, top=%d\0A\00"
@.str.1 = [6 x i8] c"write\00"
define i32 @childHandle(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %9
%11 = call i32 (...) @getpid()
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13)
%15 = call i32 (...) @getpid()
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
store i32 %15, i32* %16
%17 = load i32, i32* %5
store i32 %17, i32* %7
br label %18
18: ; preds = %39, %3
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %42
22: ; preds = %18
%23 = load i32, i32* %7
%24 = call i64 @isPrime(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
%29 = load i32, i32* %7
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
store i32 %29, i32* %30
%31 = load i32, i32* %4
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%33 = call i32 @write(i32 %31, i32* %32, i32 8)
store i32 %33, i32* %8
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %18
42: ; preds = %18
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %9
ret i32 %45
}

LLVM IR (-O2):
@.str = [29 x i8] c"child %d: bottom=%d, top=%d\0A\00"
@.str.1 = [6 x i8] c"write\00"
define i32 @childHandle(i32 %0, i32 %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %1, i32 %2)
%8 = tail call i32 (...) @getpid()
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 %8, i32* %9
%10 = icmp sgt i32 %1, %2
br i1 %10, label %28, label %11
11: ; preds = %3
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
br label %13
13: ; preds = %11, %24
%14 = phi i32 [ 0, %11 ], [ %25, %24 ]
%15 = phi i32 [ %1, %11 ], [ %26, %24 ]
%16 = tail call i64 @isPrime(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = add nsw i32 %14, 1
store i32 %15, i32* %12
%20 = call i32 @write(i32 %0, i32* %9, i32 8)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %13, %22, %18
%25 = phi i32 [ %19, %22 ], [ %19, %18 ], [ %14, %13 ]
%26 = add i32 %15, 1
%27 = icmp eq i32 %15, %2
br i1 %27, label %28, label %13
28: ; preds = %24, %3
%29 = phi i32 [ 0, %3 ], [ %25, %24 ]
%30 = tail call i32 @close(i32 %0)
ret i32 %29
}