#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 char uint8_t;
struct msghdr {
  int msg_iovlen;
  struct iovec *msg_iov;
};
struct iovec {
  char *iov_base;
  size_t iov_len;
};

/* Variables and functions */
char get_msghdr_last_char(const struct msghdr *mhdr) {
  struct iovec *iov = mhdr->msg_iov + mhdr->msg_iovlen - 1;
  uint8_t *last_buf = iov->iov_base;
  size_t last_buf_len = iov->iov_len;
  return last_buf[last_buf_len - 1];
}


x86 assembly (clang, -O0):
<get_msghdr_last_char>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
add    $0xfffffffffffffff0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_msghdr_last_char>:
mov    0x8(%rdi),%rax
movslq (%rdi),%rcx
shl    $0x4,%rcx
mov    -0x10(%rax,%rcx,1),%rdx
mov    -0x8(%rax,%rcx,1),%rax
mov    -0x1(%rax,%rdx,1),%al
ret

LLVM IR (-O0):
%struct.msghdr = type { i32, %struct.iovec* }
%struct.iovec = type { i8*, i64 }
define signext i8 @get_msghdr_last_char(%struct.msghdr* %0) {
%2 = alloca %struct.msghdr*
%3 = alloca %struct.iovec*
%4 = alloca i8*
%5 = alloca i64
store %struct.msghdr* %0, %struct.msghdr** %2
%6 = load %struct.msghdr*, %struct.msghdr** %2
%7 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i32 0, i32 1
%8 = load %struct.iovec*, %struct.iovec** %7
%9 = load %struct.msghdr*, %struct.msghdr** %2
%10 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 %12
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i64 -1
store %struct.iovec* %14, %struct.iovec** %3
%15 = load %struct.iovec*, %struct.iovec** %3
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 0
%17 = load i8*, i8** %16
store i8* %17, i8** %4
%18 = load %struct.iovec*, %struct.iovec** %3
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %18, i32 0, i32 1
%20 = load i64, i64* %19
store i64 %20, i64* %5
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
ret i8 %25
}

LLVM IR (-O2):
%struct.msghdr = type { i32, %struct.iovec* }
%struct.iovec = type { i8*, i64 }
define signext i8 @get_msghdr_last_char(%struct.msghdr* nocapture %0) {
%2 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 1
%3 = load %struct.iovec*, %struct.iovec** %2
%4 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds %struct.iovec, %struct.iovec* %3, i64 %6
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i64 -1
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %8, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add i64 %12, -1
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
ret i8 %15
}