#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);
void consumeItem(int num) {
  int i = num;
  int j;
  int bPrime = 1;
  for (j = i - 1; j > 1; j--) {
    if (i % j == 0) {
      bPrime = 0;
      break;
    }
  }
  nap(1000);
  if (bPrime)
    printf("pid %d: consumed item %d\n", getpid(), num);
  else
    printf("pid %d: consumed item %d but it's not prime\n", getpid(), num);
}


x86 assembly (clang, -O0):
<consumeItem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    118a <consumeItem+0x5a>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    1177 <consumeItem+0x47>
movl   $0x0,-0x10(%rbp)
jmp    118a <consumeItem+0x5a>
jmp    117c <consumeItem+0x4c>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1151 <consumeItem+0x21>
mov    $0x3e8,%edi
call   1030 <nap@plt>
cmpl   $0x0,-0x10(%rbp)
je     11bb <consumeItem+0x8b>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
jmp    11d3 <consumeItem+0xa3>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consumeItem>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xec3(%rip),%r14
lea    0xed6(%rip),%rcx
mov    %edi,%esi
cs nopw 0x0(%rax,%rax,1)
cmp    $0x3,%esi
jl     1164 <consumeItem+0x34>
add    $0xffffffff,%esi
mov    %ebx,%eax
cltd
idiv   %esi
test   %edx,%edx
jne    1150 <consumeItem+0x20>
mov    %rcx,%r14
mov    $0x3e8,%edi
call   1030 <nap@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"pid %d: consumed item %d\0A\00"
@.str.1 = [45 x i8] c"pid %d: consumed item %d but it's not prime\0A\00"
define void @consumeItem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %3
store i32 1, i32* %5
%7 = load i32, i32* %3
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %4
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = srem i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %5
br label %22
18: ; preds = %12
br label %19
19: ; preds = %18
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %9
22: ; preds = %17, %9
%23 = call i32 @nap(i32 1000)
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = call i32 (...) @getpid()
%28 = load i32, i32* %2
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %28)
br label %34
30: ; preds = %22
%31 = call i32 (...) @getpid()
%32 = load i32, i32* %2
%33 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %30, %26
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"pid %d: consumed item %d\0A\00"
@.str.1 = [45 x i8] c"pid %d: consumed item %d but it's not prime\0A\00"
define void @consumeItem(i32 %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i32 [ %0, %1 ], [ %4, %6 ]
%4 = add nsw i32 %3, -1
%5 = icmp sgt i32 %3, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = srem i32 %0, %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %2
9: ; preds = %6, %2
%10 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), %6 ]
%11 = tail call i32 @nap(i32 1000)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 @printf(i8* %10, i32 %12, i32 %0)
ret void
}