#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 */
struct rng {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ io_error_msg(char *, int);
scalar_t__ isupper(int);
int /*<<< orphan*/ lock_region(struct rng *, int);
int tolower(int);
void set_region_protection(struct rng *rng, int prot) {
  if (isupper(prot))
    prot = tolower(prot);
  switch (prot) {
  case 'd':
    lock_region(rng, 0);
    break;
  case 'p':
    lock_region(rng, 2);
    break;
  case 'u':
    lock_region(rng, 1);
    break;
  default:
    io_error_msg("Bad argument to protect-region %c.", prot);
    break;
  }
}


x86 assembly (clang, -O0):
<set_region_protection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     116c <set_region_protection+0x2c>
mov    -0xc(%rbp),%edi
call   1040 <tolower@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x64,%eax
je     11a2 <set_region_protection+0x62>
jmp    1180 <set_region_protection+0x40>
mov    -0x10(%rbp),%eax
sub    $0x70,%eax
je     11b2 <set_region_protection+0x72>
jmp    1191 <set_region_protection+0x51>
mov    -0x10(%rbp),%eax
sub    $0x75,%eax
je     11c5 <set_region_protection+0x85>
jmp    11d8 <set_region_protection+0x98>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <lock_region@plt>
jmp    11e7 <set_region_protection+0xa7>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   1060 <lock_region@plt>
jmp    11e7 <set_region_protection+0xa7>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1060 <lock_region@plt>
jmp    11e7 <set_region_protection+0xa7>
mov    -0xc(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1030 <io_error_msg@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_region_protection>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1050 <isupper@plt>
test   %rax,%rax
je     115d <set_region_protection+0x1d>
mov    %ebp,%edi
call   1040 <tolower@plt>
mov    %eax,%ebp
cmp    $0x75,%ebp
je     1173 <set_region_protection+0x33>
cmp    $0x70,%ebp
je     117d <set_region_protection+0x3d>
cmp    $0x64,%ebp
jne    1190 <set_region_protection+0x50>
mov    %rbx,%rdi
xor    %esi,%esi
jmp    1185 <set_region_protection+0x45>
mov    %rbx,%rdi
mov    $0x1,%esi
jmp    1185 <set_region_protection+0x45>
mov    %rbx,%rdi
mov    $0x2,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <lock_region@plt>
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <io_error_msg@plt>

LLVM IR (-O0):
%struct.rng = type { i32 }
@.str = [35 x i8] c"Bad argument to protect-region %c.\00"
define void @set_region_protection(%struct.rng* %0, i32 %1) {
%3 = alloca %struct.rng*
%4 = alloca i32
store %struct.rng* %0, %struct.rng** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = call i64 @isupper(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i32 @tolower(i32 %9)
store i32 %10, i32* %4
br label %11
11: ; preds = %8, %2
%12 = load i32, i32* %4
switch i32 %12, label %22 [
i32 100, label %13
i32 112, label %16
i32 117, label %19
]
13: ; preds = %11
%14 = load %struct.rng*, %struct.rng** %3
%15 = call i32 @lock_region(%struct.rng* %14, i32 0)
br label %25
16: ; preds = %11
%17 = load %struct.rng*, %struct.rng** %3
%18 = call i32 @lock_region(%struct.rng* %17, i32 2)
br label %25
19: ; preds = %11
%20 = load %struct.rng*, %struct.rng** %3
%21 = call i32 @lock_region(%struct.rng* %20, i32 1)
br label %25
22: ; preds = %11
%23 = load i32, i32* %4
%24 = call i32 @io_error_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19, %16, %13
ret void
}

LLVM IR (-O2):
%struct.rng = type { i32 }
@.str = [35 x i8] c"Bad argument to protect-region %c.\00"
define void @set_region_protection(%struct.rng* %0, i32 %1) {
%3 = tail call i64 @isupper(i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @tolower(i32 %1)
br label %7
7: ; preds = %5, %2
%8 = phi i32 [ %6, %5 ], [ %1, %2 ]
switch i32 %8, label %15 [
i32 100, label %9
i32 112, label %11
i32 117, label %13
]
9: ; preds = %7
%10 = tail call i32 @lock_region(%struct.rng* %0, i32 0)
br label %17
11: ; preds = %7
%12 = tail call i32 @lock_region(%struct.rng* %0, i32 2)
br label %17
13: ; preds = %7
%14 = tail call i32 @lock_region(%struct.rng* %0, i32 1)
br label %17
15: ; preds = %7
%16 = tail call i32 @io_error_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %17
17: ; preds = %15, %13, %11, %9
ret void
}