#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 */
typedef scalar_t__ const u_int;

/* Variables and functions */
int UINT_MAX;
scalar_t__ arc4random();
int /*<<< orphan*/ isalpha(unsigned char);
scalar_t__ islower(unsigned char);
scalar_t__ isupper(unsigned char);
unsigned char tolower(unsigned char);
unsigned char toupper(unsigned char);
unsigned char randomcase(unsigned char c) {
  if (!isalpha(c)) {
    return c;
  }
  const u_int cutpoint = (UINT_MAX / 2);
  u_int rand = arc4random();
  if (rand < cutpoint) {
    if (isupper(c)) {
      return tolower(c);
    }
    if (islower(c)) {
      return toupper(c);
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<randomcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
jne    118b <randomcase+0x2b>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    120e <randomcase+0xae>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <arc4random@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1208 <randomcase+0xa8>
movzbl -0x2(%rbp),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     11df <randomcase+0x7f>
movzbl -0x2(%rbp),%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbp)
jmp    120e <randomcase+0xae>
movzbl -0x2(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1203 <randomcase+0xa3>
movzbl -0x2(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,-0x1(%rbp)
jmp    120e <randomcase+0xae>
jmp    1208 <randomcase+0xa8>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomcase>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1070 <isalpha@plt>
test   %eax,%eax
je     11c4 <randomcase+0x64>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rbp
xor    %eax,%eax
call   1050 <arc4random@plt>
cmp    %rbp,%rax
jge    11c4 <randomcase+0x64>
movzbl %bl,%ebp
mov    %ebp,%edi
call   1080 <isupper@plt>
test   %rax,%rax
je     11ab <randomcase+0x4b>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <tolower@plt>
mov    %ebp,%edi
call   1030 <islower@plt>
test   %rax,%rax
je     11c4 <randomcase+0x64>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <toupper@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@UINT_MAX = global i32 0
define zeroext i8 @randomcase(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i64
%5 = alloca i64
store i8 %0, i8* %3
%6 = load i8, i8* %3
%7 = call i32 @isalpha(i8 zeroext %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = load i8, i8* %3
store i8 %10, i8* %2
br label %36
11: ; preds = %1
%12 = load i32, i32* @UINT_MAX
%13 = sdiv i32 %12, 2
%14 = sext i32 %13 to i64
store i64 %14, i64* %4
%15 = call i64 (...) @arc4random()
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = load i64, i64* %4
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %34
19: ; preds = %11
%20 = load i8, i8* %3
%21 = call i64 @isupper(i8 zeroext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8, i8* %3
%25 = call zeroext i8 @tolower(i8 zeroext %24)
store i8 %25, i8* %2
br label %36
26: ; preds = %19
%27 = load i8, i8* %3
%28 = call i64 @islower(i8 zeroext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8, i8* %3
%32 = call zeroext i8 @toupper(i8 zeroext %31)
store i8 %32, i8* %2
br label %36
33: ; preds = %26
br label %34
34: ; preds = %33, %11
%35 = load i8, i8* %3
store i8 %35, i8* %2
br label %36
36: ; preds = %34, %30, %23, %9
%37 = load i8, i8* %2
ret i8 %37
}

LLVM IR (-O2):
@UINT_MAX = global i32 0
define zeroext i8 @randomcase(i8 zeroext %0) {
%2 = tail call i32 @isalpha(i8 zeroext %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = load i32, i32* @UINT_MAX
%6 = sdiv i32 %5, 2
%7 = sext i32 %6 to i64
%8 = tail call i64 (...) @arc4random()
%9 = icmp slt i64 %8, %7
br i1 %9, label %10, label %20
10: ; preds = %4
%11 = tail call i64 @isupper(i8 zeroext %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call zeroext i8 @tolower(i8 zeroext %0)
br label %20
15: ; preds = %10
%16 = tail call i64 @islower(i8 zeroext %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call zeroext i8 @toupper(i8 zeroext %0)
br label %20
20: ; preds = %13, %18, %15, %4, %1
%21 = phi i8 [ %0, %1 ], [ %14, %13 ], [ %19, %18 ], [ %0, %15 ], [ %0, %4 ]
ret i8 %21
}