#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 getpid();
int /*<<< orphan*/ nap(int);
int /*<<< orphan*/ printf(char *, int, int);
int produceItem(int num) {
  int i = num + 1;
  int j;
  while (i < 999999) {
    for (j = i - 1; j > 1; j--) {
      if (i % j == 0)
        break;
    }
    if (j == 1)
      break;
    else
      i++;
  }
  nap(10000);
  printf("pid %d : produced %d\n", getpid(), i);
  return i;
}


x86 assembly (clang, -O0):
<produceItem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0xf423f,-0x8(%rbp)
jge    11a9 <produceItem+0x79>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    118c <produceItem+0x5c>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1179 <produceItem+0x49>
jmp    118c <produceItem+0x5c>
jmp    117e <produceItem+0x4e>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    115a <produceItem+0x2a>
cmpl   $0x1,-0xc(%rbp)
jne    119b <produceItem+0x6b>
jmp    11a9 <produceItem+0x79>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1144 <produceItem+0x14>
mov    $0x2710,%edi
call   1030 <nap@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<produceItem>:
push   %rbx
cmp    $0xf423f,%edi
mov    $0xf423e,%ecx
cmovge %edi,%ecx
lea    0x1(%rcx),%esi
jmp    1157 <produceItem+0x27>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%edi
mov    %ebx,%edi
je     1183 <produceItem+0x53>
cmp    %ecx,%edi
je     11a8 <produceItem+0x78>
lea    0x1(%rdi),%ebx
cmp    $0x2,%edi
jl     1150 <produceItem+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
cltd
idiv   %edi
test   %edx,%edx
je     1150 <produceItem+0x20>
lea    -0x1(%rdi),%eax
cmp    $0x2,%edi
mov    %eax,%edi
jg     1170 <produceItem+0x40>
mov    $0x2710,%edi
call   1030 <nap@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe65(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret
mov    %esi,%ebx
jmp    1183 <produceItem+0x53>

LLVM IR (-O0):
@.str = [22 x i8] c"pid %d : produced %d\0A\00"
define i32 @produceItem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %3
br label %7
7: ; preds = %33, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 999999
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %4
br label %13
13: ; preds = %23, %10
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = srem i32 %17, %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %26
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %13
26: ; preds = %21, %13
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %26
br label %34
30: ; preds = %26
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %30
br label %7
34: ; preds = %29, %7
%35 = call i32 @nap(i32 10000)
%36 = call i32 (...) @getpid()
%37 = load i32, i32* %3
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [22 x i8] c"pid %d : produced %d\0A\00"
define i32 @produceItem(i32 %0) {
%2 = call i32 @llvm.smax.i32(i32 %0, i32 999998)
%3 = add nuw i32 %2, 1
br label %4
4: ; preds = %17, %1
%5 = phi i32 [ %0, %1 ], [ %6, %17 ]
%6 = add i32 %5, 1
%7 = icmp eq i32 %5, %2
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = icmp sgt i32 %5, 1
br i1 %9, label %10, label %17
10: ; preds = %8, %14
%11 = phi i32 [ %15, %14 ], [ %5, %8 ]
%12 = srem i32 %6, %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = add nsw i32 %11, -1
%16 = icmp sgt i32 %11, 2
br i1 %16, label %10, label %20
17: ; preds = %10, %8
%18 = phi i32 [ %5, %8 ], [ %11, %10 ]
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %4
20: ; preds = %17, %4, %14
%21 = phi i32 [ %6, %14 ], [ %3, %4 ], [ %6, %17 ]
%22 = tail call i32 @nap(i32 10000)
%23 = tail call i32 (...) @getpid()
%24 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %21)
ret i32 %21
}