#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*/ prterr(int, char *);
int iwork(int iwkmax, int *iwkpt, int number, int itype) {
  int i;
  i = *iwkpt;
  if (itype == 2 || itype == 3)
    *iwkpt += number;
  else {
    if (i % 2 != 0)
      ++i;
    *iwkpt += (number << 1);
    i /= 2;
  }
  if (*iwkpt > iwkmax)
    prterr(40, "Out of workspace.");
  return i;
}


x86 assembly (clang, -O0):
<iwork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x18(%rbp)
je     1142 <iwork+0x32>
cmpl   $0x3,-0x18(%rbp)
jne    1152 <iwork+0x42>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    118b <iwork+0x7b>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     116f <iwork+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jle    11ab <iwork+0x9b>
mov    $0x28,%edi
lea    0xe5a(%rip),%rsi
call   1030 <prterr@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwork>:
push   %rbx
mov    (%rsi),%ebx
and    $0xfffffffe,%ecx
cmp    $0x2,%ecx
jne    1125 <iwork+0x15>
add    %ebx,%edx
mov    %edx,(%rsi)
cmp    %edi,%edx
jg     113e <iwork+0x2e>
jmp    114f <iwork+0x3f>
mov    %ebx,%eax
and    $0x1,%eax
add    %ebx,%eax
lea    (%rbx,%rdx,2),%edx
mov    %edx,(%rsi)
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
cmp    %edi,%edx
jle    114f <iwork+0x3f>
lea    0xebb(%rip),%rsi
mov    $0x28,%edi
call   1030 <prterr@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"Out of workspace.\00"
define i32 @iwork(i32 %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = load i32, i32* %1
%6 = and i32 %3, -2
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = add nsw i32 %5, %2
store i32 %9, i32* %1
br label %16
10: ; preds = %4
%11 = and i32 %5, 1
%12 = add nsw i32 %11, %5
%13 = shl i32 %2, 1
%14 = add nsw i32 %5, %13
store i32 %14, i32* %1
%15 = sdiv i32 %12, 2
br label %16
16: ; preds = %10, %8
%17 = phi i32 [ %9, %8 ], [ %14, %10 ]
%18 = phi i32 [ %5, %8 ], [ %15, %10 ]
%19 = icmp sgt i32 %17, %0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @prterr(i32 40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
ret i32 %18
}