#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
void print_segdesc(uint8_t *ptr) {
  uint32_t base_addr;
  uint32_t seg_limit;
  uint32_t v;
  int g, db, p, dpl, s, type;
  v = *ptr++;
  seg_limit = v;
  v = *ptr++;
  seg_limit |= (v << 8);
  v = *ptr++;
  base_addr = v;
  v = *ptr++;
  base_addr |= (v << 8);
  v = *ptr++;
  base_addr |= (v << 16);
  v = *ptr++;
  type = v & 0xf;
  s = (v >> 4) & 1;
  dpl = (v >> 5) & 0x3;
  p = (v >> 7) & 1;
  v = *ptr++;
  seg_limit |= (v & 0xf) << 16;
  db = (v >> 6) & 1;
  g = (v >> 7) & 1;
  v = *ptr++;
  base_addr |= (v << 24);
  printf("base addr: 0x%08x\n", base_addr);
  printf("limit:     0x%05x\n", seg_limit);
  printf("g %d, db %d, p %d, dpl %x, s %d, type %x\n", g, db, p, dpl, s, type);
}


x86 assembly (clang, -O0):
<print_segdesc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x10,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x4,%eax
and    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x5,%eax
and    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x7,%eax
and    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xf,%eax
shl    $0x10,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x6,%eax
and    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x7,%eax
and    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x18,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x2c(%rbp),%eax
lea    0xd9d(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_segdesc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x4(%rdi),%edx
mov    0xc(%rdi),%eax
shl    $0x8,%edx
or     (%rdi),%edx
shl    $0x8,%eax
or     0x8(%rdi),%eax
mov    0x10(%rdi),%ecx
shl    $0x10,%ecx
mov    0x14(%rdi),%r13d
mov    %r13d,%esi
and    $0xf,%esi
mov    %esi,0x14(%rsp)
mov    %r13d,%r14d
shr    $0x4,%r14d
and    $0x1,%r14d
mov    %r13d,%r15d
shr    $0x5,%r15d
and    $0x3,%r15d
shr    $0x7,%r13d
and    $0x1,%r13d
mov    0x18(%rdi),%ebx
mov    %ebx,%ebp
and    $0xf,%ebp
shl    $0x10,%ebp
or     %edx,%ebp
mov    %ebx,%r12d
shr    $0x6,%r12d
and    $0x1,%r12d
shr    $0x7,%ebx
and    $0x1,%ebx
mov    0x1c(%rdi),%esi
shl    $0x18,%esi
or     %ecx,%esi
or     %eax,%esi
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe75(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe71(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"base addr: 0x%08x\0A\00"
@.str.1 = [19 x i8] c"limit: 0x%05x\0A\00"
@.str.2 = [42 x i8] c"g %d, db %d, p %d, dpl %x, s %d, type %x\0A\00"
define void @print_segdesc(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %2
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i32 1
store i32* %13, i32** %2
%14 = load i32, i32* %12
store i32 %14, i32* %5
%15 = load i32, i32* %5
store i32 %15, i32* %4
%16 = load i32*, i32** %2
%17 = getelementptr inbounds i32, i32* %16, i32 1
store i32* %17, i32** %2
%18 = load i32, i32* %16
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = shl i32 %19, 8
%21 = load i32, i32* %4
%22 = or i32 %21, %20
store i32 %22, i32* %4
%23 = load i32*, i32** %2
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %2
%25 = load i32, i32* %23
store i32 %25, i32* %5
%26 = load i32, i32* %5
store i32 %26, i32* %3
%27 = load i32*, i32** %2
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %2
%29 = load i32, i32* %27
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = shl i32 %30, 8
%32 = load i32, i32* %3
%33 = or i32 %32, %31
store i32 %33, i32* %3
%34 = load i32*, i32** %2
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %2
%36 = load i32, i32* %34
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = shl i32 %37, 16
%39 = load i32, i32* %3
%40 = or i32 %39, %38
store i32 %40, i32* %3
%41 = load i32*, i32** %2
%42 = getelementptr inbounds i32, i32* %41, i32 1
store i32* %42, i32** %2
%43 = load i32, i32* %41
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = and i32 %44, 15
store i32 %45, i32* %11
%46 = load i32, i32* %5
%47 = ashr i32 %46, 4
%48 = and i32 %47, 1
store i32 %48, i32* %10
%49 = load i32, i32* %5
%50 = ashr i32 %49, 5
%51 = and i32 %50, 3
store i32 %51, i32* %9
%52 = load i32, i32* %5
%53 = ashr i32 %52, 7
%54 = and i32 %53, 1
store i32 %54, i32* %8
%55 = load i32*, i32** %2
%56 = getelementptr inbounds i32, i32* %55, i32 1
store i32* %56, i32** %2
%57 = load i32, i32* %55
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = and i32 %58, 15
%60 = shl i32 %59, 16
%61 = load i32, i32* %4
%62 = or i32 %61, %60
store i32 %62, i32* %4
%63 = load i32, i32* %5
%64 = ashr i32 %63, 6
%65 = and i32 %64, 1
store i32 %65, i32* %7
%66 = load i32, i32* %5
%67 = ashr i32 %66, 7
%68 = and i32 %67, 1
store i32 %68, i32* %6
%69 = load i32*, i32** %2
%70 = getelementptr inbounds i32, i32* %69, i32 1
store i32* %70, i32** %2
%71 = load i32, i32* %69
store i32 %71, i32* %5
%72 = load i32, i32* %5
%73 = shl i32 %72, 24
%74 = load i32, i32* %3
%75 = or i32 %74, %73
store i32 %75, i32* %3
%76 = load i32, i32* %3
%77 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %4
%79 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %78)
%80 = load i32, i32* %6
%81 = load i32, i32* %7
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = load i32, i32* %10
%85 = load i32, i32* %11
%86 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %80, i32 %81, i32 %82, i32 %83, i32 %84, i32 %85)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"base addr: 0x%08x\0A\00"
@.str.1 = [19 x i8] c"limit: 0x%05x\0A\00"
@.str.2 = [42 x i8] c"g %d, db %d, p %d, dpl %x, s %d, type %x\0A\00"
define void @print_segdesc(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 1
%3 = load i32, i32* %0
%4 = getelementptr inbounds i32, i32* %0, i64 2
%5 = load i32, i32* %2
%6 = shl i32 %5, 8
%7 = or i32 %6, %3
%8 = getelementptr inbounds i32, i32* %0, i64 3
%9 = load i32, i32* %4
%10 = getelementptr inbounds i32, i32* %0, i64 4
%11 = load i32, i32* %8
%12 = shl i32 %11, 8
%13 = or i32 %12, %9
%14 = getelementptr inbounds i32, i32* %0, i64 5
%15 = load i32, i32* %10
%16 = shl i32 %15, 16
%17 = or i32 %13, %16
%18 = getelementptr inbounds i32, i32* %0, i64 6
%19 = load i32, i32* %14
%20 = and i32 %19, 15
%21 = lshr i32 %19, 4
%22 = and i32 %21, 1
%23 = lshr i32 %19, 5
%24 = and i32 %23, 3
%25 = lshr i32 %19, 7
%26 = and i32 %25, 1
%27 = getelementptr inbounds i32, i32* %0, i64 7
%28 = load i32, i32* %18
%29 = shl i32 %28, 16
%30 = and i32 %29, 983040
%31 = or i32 %7, %30
%32 = lshr i32 %28, 6
%33 = and i32 %32, 1
%34 = lshr i32 %28, 7
%35 = and i32 %34, 1
%36 = load i32, i32* %27
%37 = shl i32 %36, 24
%38 = or i32 %17, %37
%39 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%41 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %33, i32 %26, i32 %24, i32 %22, i32 %20)
ret void
}