#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 /*<<< orphan*/ assert(int);
int fetch_present_idx(const void *struct_ptr, int pres_offset, int pres_size) {
  const void *present_ptr;
  int present;
  present_ptr = ((const char *)struct_ptr) + pres_offset;
  switch (pres_size) {
  case sizeof(int):
    present = *(const int *)present_ptr;
    break;
  case sizeof(short):
    present = *(const short *)present_ptr;
    break;
  case sizeof(char):
    present = *(const char *)present_ptr;
    break;
  default:
    assert(pres_size != sizeof(int));
    return 0;
  }
  return present;
}


x86 assembly (clang, -O0):
<fetch_present_idx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1184 <fetch_present_idx+0x74>
jmp    1145 <fetch_present_idx+0x35>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     1175 <fetch_present_idx+0x65>
jmp    1156 <fetch_present_idx+0x46>
mov    -0x28(%rbp),%eax
sub    $0x4,%eax
jne    1193 <fetch_present_idx+0x83>
jmp    1167 <fetch_present_idx+0x57>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <fetch_present_idx+0xa4>
mov    -0x20(%rbp),%rax
movswl (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <fetch_present_idx+0xa4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <fetch_present_idx+0xa4>
movslq -0x18(%rbp),%rax
cmp    $0x4,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ba <fetch_present_idx+0xaa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch_present_idx>:
push   %rax
movslq %esi,%rax
cmp    $0x1,%edx
je     1128 <fetch_present_idx+0x18>
cmp    $0x2,%edx
je     112e <fetch_present_idx+0x1e>
cmp    $0x4,%edx
jne    1134 <fetch_present_idx+0x24>
mov    (%rdi,%rax,1),%eax
pop    %rcx
ret
movsbl (%rdi,%rax,1),%eax
pop    %rcx
ret
movswl (%rdi,%rax,1),%eax
pop    %rcx
ret
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @fetch_present_idx(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8* %13, i8** %8
%14 = load i32, i32* %7
switch i32 %14, label %28 [
i32 4, label %15
i32 2, label %19
i32 1, label %24
]
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
store i32 %18, i32* %9
br label %34
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = bitcast i8* %20 to i16*
%22 = load i16, i16* %21
%23 = sext i16 %22 to i32
store i32 %23, i32* %9
br label %34
24: ; preds = %3
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
store i32 %27, i32* %9
br label %34
28: ; preds = %3
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = icmp ne i64 %30, 4
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
store i32 0, i32* %4
br label %36
34: ; preds = %24, %19, %15
%35 = load i32, i32* %9
store i32 %35, i32* %4
br label %36
36: ; preds = %34, %28
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @fetch_present_idx(i8* nocapture %0, i32 %1, i32 %2) {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
switch i32 %2, label %16 [
i32 4, label %6
i32 2, label %9
i32 1, label %13
]
6: ; preds = %3
%7 = bitcast i8* %5 to i32*
%8 = load i32, i32* %7
br label %20
9: ; preds = %3
%10 = bitcast i8* %5 to i16*
%11 = load i16, i16* %10
%12 = sext i16 %11 to i32
br label %20
13: ; preds = %3
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
br label %20
16: ; preds = %3
%17 = icmp ne i32 %2, 4
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
br label %20
20: ; preds = %6, %9, %13, %16
%21 = phi i32 [ 0, %16 ], [ %15, %13 ], [ %12, %9 ], [ %8, %6 ]
ret i32 %21
}