#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 random();
int roughly(int value) {
  if (value < 0)
    return -roughly(-value);
  else if (value <= 1)
    return value;
  else
    return value * 3 / 4 + random() % (value / 2);
}


x86 assembly (clang, -O0):
<roughly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    114d <roughly+0x2d>
xor    %edi,%edi
sub    -0x8(%rbp),%edi
call   1030 <roughly@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <roughly+0x76>
cmpl   $0x1,-0x8(%rbp)
jg     1162 <roughly+0x42>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <roughly+0x76>
imul   $0x3,-0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    -0xc(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roughly>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %edi,%edi
js     1151 <roughly+0x31>
cmp    $0x2,%ebx
jb     115e <roughly+0x3e>
lea    (%rbx,%rbx,2),%eax
lea    (%rbx,%rbx,2),%ebp
add    $0x3,%ebp
test   %eax,%eax
cmovns %eax,%ebp
sar    $0x2,%ebp
xor    %eax,%eax
call   1040 <random@plt>
shr    %ebx
cltd
idiv   %ebx
mov    %edx,%ebx
add    %ebp,%ebx
jmp    115e <roughly+0x3e>
neg    %ebx
mov    %ebx,%edi
call   1030 <roughly@plt>
mov    %eax,%ebx
neg    %ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @roughly(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sub nsw i32 0, %7
%9 = call i32 @roughly(i32 %8)
%10 = sub nsw i32 0, %9
store i32 %10, i32* %2
br label %25
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32, i32* %3
store i32 %15, i32* %2
br label %25
16: ; preds = %11
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 3
%19 = sdiv i32 %18, 4
%20 = call i32 (...) @random()
%21 = load i32, i32* %3
%22 = sdiv i32 %21, 2
%23 = srem i32 %20, %22
%24 = add nsw i32 %19, %23
store i32 %24, i32* %2
br label %25
25: ; preds = %16, %14, %6
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @roughly(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %5, label %9
3: ; preds = %11, %9, %5
%4 = phi i32 [ %8, %5 ], [ %17, %11 ], [ %0, %9 ]
ret i32 %4
5: ; preds = %1
%6 = sub nsw i32 0, %0
%7 = tail call i32 @roughly(i32 %6)
%8 = sub nsw i32 0, %7
br label %3
9: ; preds = %1
%10 = icmp ult i32 %0, 2
br i1 %10, label %3, label %11
11: ; preds = %9
%12 = mul nsw i32 %0, 3
%13 = sdiv i32 %12, 4
%14 = tail call i32 (...) @random()
%15 = lshr i32 %0, 1
%16 = srem i32 %14, %15
%17 = add nsw i32 %16, %13
br label %3
}