#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 ulong;
typedef int u_int64_t;
typedef int u_int32_t;

/* Variables and functions */
#define EAGAIN 129
#define EMSGSIZE 128
int applid2fd(unsigned int);
int capi20_isinstalled();
int /*<<< orphan*/ capimsg_setu16(unsigned char *, int, unsigned int);
int /*<<< orphan*/ cleanup_buffers_for_plci(unsigned int, unsigned char);
int errno;
unsigned char *get_buffer(unsigned int, size_t *, unsigned int *);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, unsigned char);
int read(int, unsigned char *, size_t);
int /*<<< orphan*/ return_buffer(unsigned int, unsigned int);
int /*<<< orphan*/ save_datahandle(unsigned int, unsigned int, unsigned char,
                                   unsigned char);
int /*<<< orphan*/ validapplid(unsigned int);
unsigned capi20_get_message(unsigned ApplID, unsigned char **Buf) {
  unsigned char *rcvbuf;
  unsigned offset;
  unsigned ret;
  size_t bufsiz;
  int rc, fd;
  if (capi20_isinstalled() != 0x0000)
    return 0x1009;
  if (!validapplid(ApplID))
    return 0x1101;
  fd = applid2fd(ApplID);
  if ((*Buf = rcvbuf = get_buffer(ApplID, &bufsiz, &offset)) == 0)
    return 0x1108;
  if ((rc = read(fd, rcvbuf, bufsiz)) > 0) {
    capimsg_setu16(rcvbuf, 2, ApplID);
    if ((rcvbuf[4]) == 0x86 && (rcvbuf[5]) == 0x82) {
      save_datahandle(ApplID, offset, (rcvbuf[18] | (rcvbuf[(18) + 1] << 8)),
                      (rcvbuf[8] | (rcvbuf[(8) + 1] << 8) |
                       (rcvbuf[(8) + 2] << 16) | (rcvbuf[(8) + 3] << 24)));
      capimsg_setu16(rcvbuf, 18, offset);
      if (sizeof(void *) == 4) {
        u_int32_t data =
            (u_int32_t)rcvbuf + (rcvbuf[0] | (rcvbuf[(0) + 1] << 8));
        rcvbuf[12] = data & 0xff;
        rcvbuf[13] = (data >> 8) & 0xff;
        rcvbuf[14] = (data >> 16) & 0xff;
        rcvbuf[15] = (data >> 24) & 0xff;
      } else {
        u_int64_t data;
        ulong radr = (ulong)rcvbuf;
        if ((rcvbuf[0] | (rcvbuf[(0) + 1] << 8)) < 30) {
          memmove(rcvbuf + 30, rcvbuf + (rcvbuf[0] | (rcvbuf[(0) + 1] << 8)),
                  (rcvbuf[16] | (rcvbuf[(16) + 1] << 8)));
          rcvbuf[0] = 30;
          rcvbuf[1] = 0;
        }
        data = radr + (rcvbuf[0] | (rcvbuf[(0) + 1] << 8));
        rcvbuf[12] = rcvbuf[13] = rcvbuf[14] = rcvbuf[15] = 0;
        rcvbuf[22] = data & 0xff;
        rcvbuf[23] = (data >> 8) & 0xff;
        rcvbuf[24] = (data >> 16) & 0xff;
        rcvbuf[25] = (data >> 24) & 0xff;
        rcvbuf[26] = (data >> 32) & 0xff;
        rcvbuf[27] = (data >> 40) & 0xff;
        rcvbuf[28] = (data >> 48) & 0xff;
        rcvbuf[29] = (data >> 56) & 0xff;
      }
      return 0x0000;
    }
    return_buffer(ApplID, offset);
    if ((rcvbuf[4]) == 0x04 && (rcvbuf[5]) == 0x82)
      cleanup_buffers_for_plci(ApplID, (rcvbuf[8] | (rcvbuf[(8) + 1] << 8) |
                                        (rcvbuf[(8) + 2] << 16) |
                                        (rcvbuf[(8) + 3] << 24)));
    return 0x0000;
  }
  return_buffer(ApplID, offset);
  if (rc == 0)
    return 0x1104;
  switch (errno) {
  case EMSGSIZE:
    ret = 0x1102;
    break;
  case EAGAIN:
    return 0x1104;
  default:
    ret = 0x1108;
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<capi20_get_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <capi20_isinstalled@plt>
cmp    $0x0,%eax
je     11cb <capi20_get_message+0x2b>
movl   $0x1009,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    -0x8(%rbp),%edi
call   10c0 <validapplid@plt>
cmp    $0x0,%eax
jne    11e8 <capi20_get_message+0x48>
movl   $0x1101,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    -0x8(%rbp),%edi
call   1050 <applid2fd@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10b0 <get_buffer@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1224 <capi20_get_message+0x84>
movl   $0x1108,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    14be <capi20_get_message+0x31e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0x2,%esi
call   1030 <capimsg_setu16@plt>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x86,%eax
jne    1449 <capi20_get_message+0x2a9>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x82,%eax
jne    1449 <capi20_get_message+0x2a9>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
movzbl 0x12(%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x13(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
movzbl 0x8(%rax),%eax
mov    -0x18(%rbp),%rdx
movzbl 0x9(%rdx),%edx
shl    $0x8,%edx
or     %edx,%eax
mov    -0x18(%rbp),%rdx
movzbl 0xa(%rdx),%edx
shl    $0x10,%edx
or     %edx,%eax
mov    -0x18(%rbp),%rdx
movzbl 0xb(%rdx),%edx
shl    $0x18,%edx
or     %edx,%eax
movzbl %cl,%edx
movzbl %al,%ecx
call   1080 <save_datahandle@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x12,%esi
call   1030 <capimsg_setu16@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
cmp    $0x1e,%eax
jge    1354 <capi20_get_message+0x1b4>
mov    -0x18(%rbp),%rdi
add    $0x1e,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
cltq
add    %rax,%rsi
mov    -0x18(%rbp),%rax
movzbl 0x10(%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x11(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl %al,%edx
call   1090 <memmove@plt>
mov    -0x18(%rbp),%rax
movb   $0x1e,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x38(%rbp),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
mov    -0x18(%rbp),%rdx
movzbl 0x1(%rdx),%edx
shl    $0x8,%edx
or     %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,0xf(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xe(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xd(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xc(%rax)
mov    -0x34(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x16(%rax)
mov    -0x34(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x17(%rax)
mov    -0x34(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x18(%rax)
mov    -0x34(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x19(%rax)
mov    -0x34(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1a(%rax)
mov    -0x34(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1b(%rax)
mov    -0x34(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1c(%rax)
mov    -0x34(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1d(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <return_buffer@plt>
mov    -0x18(%rbp),%rax
movzbl 0x4(%rax),%eax
cmp    $0x4,%eax
jne    14b2 <capi20_get_message+0x312>
mov    -0x18(%rbp),%rax
movzbl 0x5(%rax),%eax
cmp    $0x82,%eax
jne    14b2 <capi20_get_message+0x312>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rax
movzbl 0x8(%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x9(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
movzbl 0xa(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%rcx
movzbl 0xb(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
movzbl %al,%esi
call   10a0 <cleanup_buffers_for_plci@plt>
movl   $0x0,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <return_buffer@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    14df <capi20_get_message+0x33f>
movl   $0x1104,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
mov    0x2afa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x80,%eax
je     150e <capi20_get_message+0x36e>
jmp    14fb <capi20_get_message+0x35b>
mov    -0x3c(%rbp),%eax
sub    $0x81,%eax
je     151a <capi20_get_message+0x37a>
jmp    1526 <capi20_get_message+0x386>
movl   $0x1102,-0x20(%rbp)
jmp    152d <capi20_get_message+0x38d>
movl   $0x1104,-0x4(%rbp)
jmp    1533 <capi20_get_message+0x393>
movl   $0x1108,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capi20_get_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
xor    %eax,%eax
call   1070 <capi20_isinstalled@plt>
mov    $0x1009,%ebx
test   %eax,%eax
je     11cd <capi20_get_message+0x2d>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   10c0 <validapplid@plt>
test   %eax,%eax
je     12ce <capi20_get_message+0x12e>
mov    %r14d,%edi
call   1050 <applid2fd@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   10b0 <get_buffer@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     1341 <capi20_get_message+0x1a1>
mov    %rax,%rbx
mov    0x10(%rsp),%rdx
mov    %r15d,%edi
mov    %rax,%rsi
call   1060 <read@plt>
test   %eax,%eax
jle    130b <capi20_get_message+0x16b>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14d,%edx
call   1030 <capimsg_setu16@plt>
cmpb   $0x86,0x4(%rbx)
mov    %rbx,%rbp
jne    12d8 <capi20_get_message+0x138>
cmpb   $0x82,0x5(%rbp)
jne    12d8 <capi20_get_message+0x138>
mov    0xc(%rsp),%esi
movzbl 0x12(%rbp),%edx
movzbl 0x8(%rbp),%ecx
mov    %r14d,%edi
call   1080 <save_datahandle@plt>
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
mov    $0x12,%esi
call   1030 <capimsg_setu16@plt>
movzbl 0x0(%rbp),%eax
movzbl 0x1(%rbp),%ecx
mov    %rcx,%rsi
shl    $0x8,%rsi
or     %rax,%rsi
cmp    $0x1d,%esi
ja     129f <capi20_get_message+0xff>
lea    0x1e(%rbp),%rdi
add    %rbp,%rsi
movzbl 0x10(%rbp),%edx
call   1090 <memmove@plt>
movw   $0x1e,0x0(%rbp)
mov    $0x1e,%al
xor    %ecx,%ecx
movzbl %al,%edx
movzbl %cl,%eax
shl    $0x8,%eax
or     %edx,%eax
add    %ebp,%eax
movl   $0x0,0xc(%rbp)
mov    %al,0x16(%rbp)
mov    %ah,0x17(%rbp)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x18(%rbp)
shr    $0x18,%eax
mov    %al,0x19(%rbp)
xor    %ebx,%ebx
jmp    11c0 <capi20_get_message+0x20>
mov    $0x1101,%ebx
jmp    11c0 <capi20_get_message+0x20>
mov    0xc(%rsp),%esi
mov    %r14d,%edi
call   1040 <return_buffer@plt>
xor    %ebx,%ebx
cmpb   $0x4,0x4(%rbp)
jne    11c0 <capi20_get_message+0x20>
cmpb   $0x82,0x5(%rbp)
jne    11c0 <capi20_get_message+0x20>
movzbl 0x8(%rbp),%esi
mov    %r14d,%edi
call   10a0 <cleanup_buffers_for_plci@plt>
jmp    11c0 <capi20_get_message+0x20>
mov    %eax,%ebp
mov    0xc(%rsp),%esi
mov    %r14d,%edi
call   1040 <return_buffer@plt>
mov    $0x1104,%ebx
test   %ebp,%ebp
je     11c0 <capi20_get_message+0x20>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
cmp    $0x80,%eax
je     134b <capi20_get_message+0x1ab>
cmp    $0x81,%eax
je     11c0 <capi20_get_message+0x20>
mov    $0x1108,%ebx
jmp    11c0 <capi20_get_message+0x20>
mov    $0x1102,%ebx
jmp    11c0 <capi20_get_message+0x20>

LLVM IR (-O0):
@errno = global i32 0
define i32 @capi20_get_message(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @capi20_isinstalled()
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 4105, i32* %3
br label %261
17: ; preds = %2
%18 = load i32, i32* %4
%19 = call i32 @validapplid(i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 4353, i32* %3
br label %261
22: ; preds = %17
%23 = load i32, i32* %4
%24 = call i32 @applid2fd(i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %4
%26 = call i8* @get_buffer(i32 %25, i64* %9, i32* %7)
store i8* %26, i8** %6
%27 = load i8**, i8*** %5
store i8* %26, i8** %27
%28 = icmp eq i8* %26, null
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 4360, i32* %3
br label %261
30: ; preds = %22
%31 = load i32, i32* %11
%32 = load i8*, i8** %6
%33 = load i64, i64* %9
%34 = call i32 @read(i32 %31, i8* %32, i64 %33)
store i32 %34, i32* %10
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %247
36: ; preds = %30
%37 = load i8*, i8** %6
%38 = load i32, i32* %4
%39 = call i32 @capimsg_setu16(i8* %37, i32 2, i32 %38)
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 4
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 134
br i1 %44, label %45, label %205
45: ; preds = %36
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 5
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = icmp eq i32 %49, 130
br i1 %50, label %51, label %205
51: ; preds = %45
%52 = load i32, i32* %4
%53 = load i32, i32* %7
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i64 18
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i64 19
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = shl i32 %61, 8
%63 = or i32 %57, %62
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i64 8
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i64 9
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = shl i32 %72, 8
%74 = or i32 %68, %73
%75 = load i8*, i8** %6
%76 = getelementptr inbounds i8, i8* %75, i64 10
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = shl i32 %78, 16
%80 = or i32 %74, %79
%81 = load i8*, i8** %6
%82 = getelementptr inbounds i8, i8* %81, i64 11
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = shl i32 %84, 24
%86 = or i32 %80, %85
%87 = trunc i32 %86 to i8
%88 = call i32 @save_datahandle(i32 %52, i32 %53, i8 zeroext %64, i8 zeroext %87)
%89 = load i8*, i8** %6
%90 = load i32, i32* %7
%91 = call i32 @capimsg_setu16(i8* %89, i32 18, i32 %90)
%92 = load i8*, i8** %6
%93 = ptrtoint i8* %92 to i32
store i32 %93, i32* %13
%94 = load i8*, i8** %6
%95 = getelementptr inbounds i8, i8* %94, i64 0
%96 = load i8, i8* %95
%97 = zext i8 %96 to i32
%98 = load i8*, i8** %6
%99 = getelementptr inbounds i8, i8* %98, i64 1
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = shl i32 %101, 8
%103 = or i32 %97, %102
%104 = icmp slt i32 %103, 30
br i1 %104, label %105, label %137
105: ; preds = %51
%106 = load i8*, i8** %6
%107 = getelementptr inbounds i8, i8* %106, i64 30
%108 = load i8*, i8** %6
%109 = load i8*, i8** %6
%110 = getelementptr inbounds i8, i8* %109, i64 0
%111 = load i8, i8* %110
%112 = zext i8 %111 to i32
%113 = load i8*, i8** %6
%114 = getelementptr inbounds i8, i8* %113, i64 1
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = shl i32 %116, 8
%118 = or i32 %112, %117
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8, i8* %108, i64 %119
%121 = load i8*, i8** %6
%122 = getelementptr inbounds i8, i8* %121, i64 16
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = load i8*, i8** %6
%126 = getelementptr inbounds i8, i8* %125, i64 17
%127 = load i8, i8* %126
%128 = zext i8 %127 to i32
%129 = shl i32 %128, 8
%130 = or i32 %124, %129
%131 = trunc i32 %130 to i8
%132 = call i32 @memmove(i8* %107, i8* %120, i8 zeroext %131)
%133 = load i8*, i8** %6
%134 = getelementptr inbounds i8, i8* %133, i64 0
store i8 30, i8* %134
%135 = load i8*, i8** %6
%136 = getelementptr inbounds i8, i8* %135, i64 1
store i8 0, i8* %136
br label %137
137: ; preds = %105, %51
%138 = load i32, i32* %13
%139 = load i8*, i8** %6
%140 = getelementptr inbounds i8, i8* %139, i64 0
%141 = load i8, i8* %140
%142 = zext i8 %141 to i32
%143 = load i8*, i8** %6
%144 = getelementptr inbounds i8, i8* %143, i64 1
%145 = load i8, i8* %144
%146 = zext i8 %145 to i32
%147 = shl i32 %146, 8
%148 = or i32 %142, %147
%149 = add nsw i32 %138, %148
store i32 %149, i32* %12
%150 = load i8*, i8** %6
%151 = getelementptr inbounds i8, i8* %150, i64 15
store i8 0, i8* %151
%152 = load i8*, i8** %6
%153 = getelementptr inbounds i8, i8* %152, i64 14
store i8 0, i8* %153
%154 = load i8*, i8** %6
%155 = getelementptr inbounds i8, i8* %154, i64 13
store i8 0, i8* %155
%156 = load i8*, i8** %6
%157 = getelementptr inbounds i8, i8* %156, i64 12
store i8 0, i8* %157
%158 = load i32, i32* %12
%159 = and i32 %158, 255
%160 = trunc i32 %159 to i8
%161 = load i8*, i8** %6
%162 = getelementptr inbounds i8, i8* %161, i64 22
store i8 %160, i8* %162
%163 = load i32, i32* %12
%164 = ashr i32 %163, 8
%165 = and i32 %164, 255
%166 = trunc i32 %165 to i8
%167 = load i8*, i8** %6
%168 = getelementptr inbounds i8, i8* %167, i64 23
store i8 %166, i8* %168
%169 = load i32, i32* %12
%170 = ashr i32 %169, 16
%171 = and i32 %170, 255
%172 = trunc i32 %171 to i8
%173 = load i8*, i8** %6
%174 = getelementptr inbounds i8, i8* %173, i64 24
store i8 %172, i8* %174
%175 = load i32, i32* %12
%176 = ashr i32 %175, 24
%177 = and i32 %176, 255
%178 = trunc i32 %177 to i8
%179 = load i8*, i8** %6
%180 = getelementptr inbounds i8, i8* %179, i64 25
store i8 %178, i8* %180
%181 = load i32, i32* %12
%182 = ashr i32 %181, 32
%183 = and i32 %182, 255
%184 = trunc i32 %183 to i8
%185 = load i8*, i8** %6
%186 = getelementptr inbounds i8, i8* %185, i64 26
store i8 %184, i8* %186
%187 = load i32, i32* %12
%188 = ashr i32 %187, 40
%189 = and i32 %188, 255
%190 = trunc i32 %189 to i8
%191 = load i8*, i8** %6
%192 = getelementptr inbounds i8, i8* %191, i64 27
store i8 %190, i8* %192
%193 = load i32, i32* %12
%194 = ashr i32 %193, 48
%195 = and i32 %194, 255
%196 = trunc i32 %195 to i8
%197 = load i8*, i8** %6
%198 = getelementptr inbounds i8, i8* %197, i64 28
store i8 %196, i8* %198
%199 = load i32, i32* %12
%200 = ashr i32 %199, 56
%201 = and i32 %200, 255
%202 = trunc i32 %201 to i8
%203 = load i8*, i8** %6
%204 = getelementptr inbounds i8, i8* %203, i64 29
store i8 %202, i8* %204
store i32 0, i32* %3
br label %261
205: ; preds = %45, %36
%206 = load i32, i32* %4
%207 = load i32, i32* %7
%208 = call i32 @return_buffer(i32 %206, i32 %207)
%209 = load i8*, i8** %6
%210 = getelementptr inbounds i8, i8* %209, i64 4
%211 = load i8, i8* %210
%212 = zext i8 %211 to i32
%213 = icmp eq i32 %212, 4
br i1 %213, label %214, label %246
214: ; preds = %205
%215 = load i8*, i8** %6
%216 = getelementptr inbounds i8, i8* %215, i64 5
%217 = load i8, i8* %216
%218 = zext i8 %217 to i32
%219 = icmp eq i32 %218, 130
br i1 %219, label %220, label %246
220: ; preds = %214
%221 = load i32, i32* %4
%222 = load i8*, i8** %6
%223 = getelementptr inbounds i8, i8* %222, i64 8
%224 = load i8, i8* %223
%225 = zext i8 %224 to i32
%226 = load i8*, i8** %6
%227 = getelementptr inbounds i8, i8* %226, i64 9
%228 = load i8, i8* %227
%229 = zext i8 %228 to i32
%230 = shl i32 %229, 8
%231 = or i32 %225, %230
%232 = load i8*, i8** %6
%233 = getelementptr inbounds i8, i8* %232, i64 10
%234 = load i8, i8* %233
%235 = zext i8 %234 to i32
%236 = shl i32 %235, 16
%237 = or i32 %231, %236
%238 = load i8*, i8** %6
%239 = getelementptr inbounds i8, i8* %238, i64 11
%240 = load i8, i8* %239
%241 = zext i8 %240 to i32
%242 = shl i32 %241, 24
%243 = or i32 %237, %242
%244 = trunc i32 %243 to i8
%245 = call i32 @cleanup_buffers_for_plci(i32 %221, i8 zeroext %244)
br label %246
246: ; preds = %220, %214, %205
store i32 0, i32* %3
br label %261
247: ; preds = %30
%248 = load i32, i32* %4
%249 = load i32, i32* %7
%250 = call i32 @return_buffer(i32 %248, i32 %249)
%251 = load i32, i32* %10
%252 = icmp eq i32 %251, 0
br i1 %252, label %253, label %254
253: ; preds = %247
store i32 4356, i32* %3
br label %261
254: ; preds = %247
%255 = load i32, i32* @errno
switch i32 %255, label %258 [
i32 128, label %256
i32 129, label %257
]
256: ; preds = %254
store i32 4354, i32* %8
br label %259
257: ; preds = %254
store i32 4356, i32* %3
br label %261
258: ; preds = %254
store i32 4360, i32* %8
br label %259
259: ; preds = %258, %256
%260 = load i32, i32* %8
store i32 %260, i32* %3
br label %261
261: ; preds = %259, %257, %253, %246, %137, %29, %21, %16
%262 = load i32, i32* %3
ret i32 %262
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @capi20_get_message(i32 %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i32* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 (...) @capi20_isinstalled()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %98
9: ; preds = %2
%10 = tail call i32 @validapplid(i32 %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %98, label %12
12: ; preds = %9
%13 = tail call i32 @applid2fd(i32 %0)
%14 = call i8* @get_buffer(i32 %0, i64* %4, i32* %3)
store i8* %14, i8** %1
%15 = icmp eq i8* %14, null
br i1 %15, label %98, label %16
16: ; preds = %12
%17 = load i64, i64* %4
%18 = call i32 @read(i32 %13, i8* %14, i64 %17)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %89
20: ; preds = %16
%21 = call i32 @capimsg_setu16(i8* %14, i32 2, i32 %0)
%22 = getelementptr inbounds i8, i8* %14, i64 4
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, -122
br i1 %24, label %25, label %76
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %14, i64 5
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, -126
br i1 %28, label %29, label %76
29: ; preds = %25
%30 = load i32, i32* %3
%31 = getelementptr inbounds i8, i8* %14, i64 18
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %14, i64 8
%34 = load i8, i8* %33
%35 = call i32 @save_datahandle(i32 %0, i32 %30, i8 zeroext %32, i8 zeroext %34)
%36 = load i32, i32* %3
%37 = call i32 @capimsg_setu16(i8* %14, i32 18, i32 %36)
%38 = ptrtoint i8* %14 to i64
%39 = trunc i64 %38 to i32
%40 = load i8, i8* %14
%41 = zext i8 %40 to i32
%42 = getelementptr inbounds i8, i8* %14, i64 1
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = shl nuw nsw i32 %44, 8
%46 = or i32 %45, %41
%47 = icmp ult i32 %46, 30
br i1 %47, label %48, label %55
48: ; preds = %29
%49 = getelementptr inbounds i8, i8* %14, i64 30
%50 = zext i32 %46 to i64
%51 = getelementptr inbounds i8, i8* %14, i64 %50
%52 = getelementptr inbounds i8, i8* %14, i64 16
%53 = load i8, i8* %52
%54 = call i32 @memmove(i8* %49, i8* %51, i8 zeroext %53)
store i8 30, i8* %14
store i8 0, i8* %42
br label %55
55: ; preds = %48, %29
%56 = phi i8 [ 0, %48 ], [ %43, %29 ]
%57 = phi i8 [ 30, %48 ], [ %40, %29 ]
%58 = zext i8 %57 to i32
%59 = zext i8 %56 to i32
%60 = shl nuw nsw i32 %59, 8
%61 = or i32 %60, %58
%62 = add nsw i32 %61, %39
%63 = getelementptr inbounds i8, i8* %14, i64 12
%64 = trunc i32 %62 to i8
%65 = getelementptr inbounds i8, i8* %14, i64 22
%66 = bitcast i8* %63 to i32*
store i32 0, i32* %66
store i8 %64, i8* %65
%67 = lshr i32 %62, 8
%68 = trunc i32 %67 to i8
%69 = getelementptr inbounds i8, i8* %14, i64 23
store i8 %68, i8* %69
%70 = lshr i32 %62, 16
%71 = trunc i32 %70 to i8
%72 = getelementptr inbounds i8, i8* %14, i64 24
store i8 %71, i8* %72
%73 = lshr i32 %62, 24
%74 = trunc i32 %73 to i8
%75 = getelementptr inbounds i8, i8* %14, i64 25
store i8 %74, i8* %75
br label %98
76: ; preds = %25, %20
%77 = load i32, i32* %3
%78 = call i32 @return_buffer(i32 %0, i32 %77)
%79 = load i8, i8* %22
%80 = icmp eq i8 %79, 4
br i1 %80, label %81, label %98
81: ; preds = %76
%82 = getelementptr inbounds i8, i8* %14, i64 5
%83 = load i8, i8* %82
%84 = icmp eq i8 %83, -126
br i1 %84, label %85, label %98
85: ; preds = %81
%86 = getelementptr inbounds i8, i8* %14, i64 8
%87 = load i8, i8* %86
%88 = call i32 @cleanup_buffers_for_plci(i32 %0, i8 zeroext %87)
br label %98
89: ; preds = %16
%90 = load i32, i32* %3
%91 = call i32 @return_buffer(i32 %0, i32 %90)
%92 = icmp eq i32 %18, 0
br i1 %92, label %98, label %93
93: ; preds = %89
%94 = load i32, i32* @errno
switch i32 %94, label %95 [
i32 128, label %96
i32 129, label %98
]
95: ; preds = %93
br label %96
96: ; preds = %93, %95
%97 = phi i32 [ 4360, %95 ], [ 4354, %93 ]
br label %98
98: ; preds = %93, %89, %76, %81, %85, %12, %9, %2, %96, %55
%99 = phi i32 [ 0, %55 ], [ %97, %96 ], [ 4105, %2 ], [ 4353, %9 ], [ 4360, %12 ], [ 0, %85 ], [ 0, %81 ], [ 0, %76 ], [ 4356, %89 ], [ 4356, %93 ]
ret i32 %99
}