#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 int dev_t;

/* Variables and functions */
int /*<<< orphan*/ die(char *, int);
int has_partitions(int);
int master(int device) {
  int mask;
  if ((unsigned int)((((dev_t)(device) >> 8) & 0xfff) |
                     ((unsigned int)((dev_t)(device) >> 32) & ~0xfff)) == 2)
    return device;
  mask = has_partitions(device);
  if (!mask)
    die("master:  Not a valid device  0x%04X", device);
  return device & mask;
}


x86 assembly (clang, -O0):
<master>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xfff,%eax
mov    -0x8(%rbp),%edx
mov    $0x20,%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    $0xfffff000,%ecx
or     %ecx,%eax
cmp    $0x2,%eax
jne    115e <master+0x3e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <master+0x6b>
mov    -0x8(%rbp),%edi
call   1040 <has_partitions@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1182 <master+0x62>
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1030 <die@plt>
mov    -0x8(%rbp),%eax
and    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<master>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1040 <has_partitions@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    113e <master+0x1e>
lea    0xec9(%rip),%rdi
mov    %ebx,%esi
call   1030 <die@plt>
and    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"master: Not a valid device 0x%04X\00"
define i32 @master(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = ashr i32 %5, 8
%7 = and i32 %6, 4095
%8 = load i32, i32* %3
%9 = ashr i32 %8, 32
%10 = and i32 %9, -4096
%11 = or i32 %7, %10
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %3
store i32 %14, i32* %2
br label %27
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @has_partitions(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* %3
%22 = call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %15
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = and i32 %24, %25
store i32 %26, i32* %2
br label %27
27: ; preds = %23, %13
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [36 x i8] c"master: Not a valid device 0x%04X\00"
define i32 @master(i32 %0) {
%2 = tail call i32 @has_partitions(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %6
6: ; preds = %1, %4
%7 = and i32 %2, %0
ret i32 %7
}