#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ msg(int, char *);
uint64_t read_int(char **from, size_t len, const char *max) {
  uint64_t result = 0;
  int i;
  if (*from + len > max) {
    msg(-3, "Attempt to read beyond end of file, corrupt file?\n");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < len; i++)
    result += (((*from)[i] & 0xff) << (8 * i));
  *from += len;
  return result;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    116c <read_int+0x4c>
mov    $0xfffffffd,%edi
lea    0xea7(%rip),%rsi
call   1040 <msg@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b6 <read_int+0x96>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
mov    -0x20(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
mov    %eax,%ecx
movsbl -0x19(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <read_int+0x53>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movsbl -0x19(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rax
mov    (%rdi),%r9
lea    (%r9,%rsi,1),%r8
cmp    %rdx,%r8
ja     1623 <read_int+0x503>
test   %rsi,%rsi
je     1146 <read_int+0x26>
cmp    $0x10,%rsi
jae    114d <read_int+0x2d>
xor    %r11d,%r11d
xor    %eax,%eax
jmp    15b9 <read_int+0x499>
xor    %eax,%eax
jmp    15e5 <read_int+0x4c5>
mov    %rsi,%r11
and    $0xfffffffffffffff0,%r11
lea    -0x10(%r11),%rax
mov    %rax,%r10
shr    $0x4,%r10
add    $0x1,%r10
test   %rax,%rax
je     15ea <read_int+0x4ca>
mov    %r10,%rax
and    $0xfffffffffffffffe,%rax
movdqa 0xec4(%rip),%xmm9
movdqa 0xecb(%rip),%xmm15
movdqa 0xed2(%rip),%xmm14
movdqa 0xed9(%rip),%xmm12
pxor   %xmm13,%xmm13
xor    %ecx,%ecx
movdqa 0xed9(%rip),%xmm10
movdqa 0xee0(%rip),%xmm11
pxor   %xmm5,%xmm5
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqu (%r9,%rcx,1),%xmm2
movdqa %xmm2,%xmm6
punpcklbw %xmm13,%xmm6
movdqa %xmm6,%xmm0
punpcklwd %xmm13,%xmm0
punpckhwd %xmm13,%xmm6
punpckhbw %xmm13,%xmm2
movdqa %xmm2,%xmm1
punpcklwd %xmm13,%xmm1
punpckhwd %xmm13,%xmm2
movdqa %xmm9,%xmm4
pslld  $0x1a,%xmm4
paddd  %xmm10,%xmm4
cvttps2dq %xmm4,%xmm4
pshufd $0xf5,%xmm2,%xmm8
pmuludq %xmm4,%xmm2
pshufd $0xe8,%xmm2,%xmm7
pshufd $0xf5,%xmm4,%xmm2
pmuludq %xmm8,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm7
movdqa %xmm15,%xmm2
pslld  $0x1a,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm1,%xmm4
pmuludq %xmm2,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm4,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm14,%xmm2
pslld  $0x1a,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm6,%xmm4
pmuludq %xmm2,%xmm6
pshufd $0xe8,%xmm6,%xmm3
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm4,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm3
movdqa %xmm12,%xmm2
pslld  $0x1a,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm0,%xmm4
pmuludq %xmm2,%xmm0
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm4,%xmm2
movdqu 0x10(%r9,%rcx,1),%xmm4
pshufd $0xe8,%xmm0,%xmm6
pshufd $0xe8,%xmm2,%xmm0
punpckldq %xmm0,%xmm6
movdqa %xmm9,%xmm0
pslld  $0x3,%xmm0
pand   %xmm11,%xmm6
pand   %xmm11,%xmm3
packuswb %xmm3,%xmm6
movdqa %xmm15,%xmm2
pslld  $0x3,%xmm2
pand   %xmm11,%xmm1
pand   %xmm11,%xmm7
packuswb %xmm7,%xmm1
packuswb %xmm1,%xmm6
paddb  %xmm5,%xmm6
movdqa %xmm4,%xmm7
punpckhbw %xmm13,%xmm4
movdqa %xmm4,%xmm1
punpckhwd %xmm13,%xmm4
movdqa 0xd88(%rip),%xmm8
paddd  %xmm8,%xmm0
pslld  $0x17,%xmm0
paddd  %xmm10,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm4,%xmm3
pmuludq %xmm0,%xmm4
pshufd $0xf5,%xmm0,%xmm5
pmuludq %xmm3,%xmm5
movdqa %xmm14,%xmm3
pslld  $0x3,%xmm3
punpcklbw %xmm13,%xmm7
punpcklwd %xmm13,%xmm1
paddd  %xmm8,%xmm2
pshufd $0xe8,%xmm4,%xmm0
pshufd $0xe8,%xmm5,%xmm4
punpckldq %xmm4,%xmm0
pslld  $0x17,%xmm2
paddd  %xmm10,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm1,%xmm4
pmuludq %xmm2,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm4,%xmm2
movdqa %xmm7,%xmm4
punpckhwd %xmm13,%xmm7
paddd  %xmm8,%xmm3
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pslld  $0x17,%xmm3
paddd  %xmm10,%xmm3
cvttps2dq %xmm3,%xmm2
pshufd $0xf5,%xmm7,%xmm3
pmuludq %xmm2,%xmm7
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
movdqa %xmm12,%xmm3
pslld  $0x3,%xmm3
punpcklwd %xmm13,%xmm4
paddd  %xmm8,%xmm3
pshufd $0xe8,%xmm7,%xmm7
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm7
pslld  $0x17,%xmm3
paddd  %xmm10,%xmm3
cvttps2dq %xmm3,%xmm2
pshufd $0xf5,%xmm4,%xmm3
pmuludq %xmm2,%xmm4
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
pshufd $0xe8,%xmm4,%xmm5
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm5
pand   %xmm11,%xmm5
pand   %xmm11,%xmm7
packuswb %xmm7,%xmm5
pand   %xmm11,%xmm1
pand   %xmm11,%xmm0
packuswb %xmm0,%xmm1
packuswb %xmm1,%xmm5
paddb  %xmm6,%xmm5
add    $0x20,%rcx
movdqa 0xc70(%rip),%xmm0
paddd  %xmm0,%xmm12
paddd  %xmm0,%xmm14
paddd  %xmm0,%xmm15
paddd  %xmm0,%xmm9
add    $0xfffffffffffffffe,%rax
jne    11c0 <read_int+0xa0>
pslld  $0x3,%xmm12
pslld  $0x3,%xmm14
pslld  $0x3,%xmm15
pslld  $0x3,%xmm9
test   $0x1,%r10b
je     159f <read_int+0x47f>
movdqu (%r9,%rcx,1),%xmm2
pxor   %xmm1,%xmm1
movdqa %xmm2,%xmm4
punpcklbw %xmm1,%xmm4
movdqa %xmm4,%xmm0
punpcklwd %xmm1,%xmm0
punpckhwd %xmm1,%xmm4
punpckhbw %xmm1,%xmm2
movdqa %xmm2,%xmm6
punpcklwd %xmm1,%xmm6
punpckhwd %xmm1,%xmm2
pslld  $0x17,%xmm9
movdqa 0xbc3(%rip),%xmm8
paddd  %xmm8,%xmm9
cvttps2dq %xmm9,%xmm7
pshufd $0xf5,%xmm2,%xmm1
pmuludq %xmm7,%xmm2
pshufd $0xe8,%xmm2,%xmm3
pshufd $0xf5,%xmm7,%xmm2
pmuludq %xmm1,%xmm2
pshufd $0xe8,%xmm2,%xmm1
punpckldq %xmm1,%xmm3
pslld  $0x17,%xmm15
paddd  %xmm8,%xmm15
cvttps2dq %xmm15,%xmm1
pshufd $0xf5,%xmm6,%xmm7
pmuludq %xmm1,%xmm6
pshufd $0xe8,%xmm6,%xmm2
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm7,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm2
pslld  $0x17,%xmm14
paddd  %xmm8,%xmm14
cvttps2dq %xmm14,%xmm1
pshufd $0xf5,%xmm4,%xmm6
pmuludq %xmm1,%xmm4
pshufd $0xe8,%xmm4,%xmm4
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm6,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm4
pslld  $0x17,%xmm12
paddd  %xmm8,%xmm12
cvttps2dq %xmm12,%xmm1
pshufd $0xf5,%xmm0,%xmm6
pmuludq %xmm1,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm6,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
movdqa 0xb11(%rip),%xmm1
pand   %xmm1,%xmm0
pand   %xmm1,%xmm4
packuswb %xmm4,%xmm0
pand   %xmm1,%xmm2
pand   %xmm1,%xmm3
packuswb %xmm3,%xmm2
packuswb %xmm2,%xmm0
paddb  %xmm0,%xmm5
pshufd $0xee,%xmm5,%xmm0
paddb  %xmm5,%xmm0
pxor   %xmm1,%xmm1
psadbw %xmm0,%xmm1
movd   %xmm1,%eax
cmp    %rsi,%r11
je     15e5 <read_int+0x4c5>
lea    0x0(,%r11,8),%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r9,%r11,1),%edx
shl    %cl,%edx
add    %dl,%al
add    $0x1,%r11
add    $0x8,%ecx
cmp    %r11,%rsi
jne    15d0 <read_int+0x4b0>
mov    %r8,(%rdi)
pop    %rcx
ret
movdqa 0xa0d(%rip),%xmm9
movdqa 0xa14(%rip),%xmm15
movdqa 0xa1b(%rip),%xmm14
movdqa 0xa22(%rip),%xmm12
pxor   %xmm5,%xmm5
xor    %ecx,%ecx
test   $0x1,%r10b
jne    1480 <read_int+0x360>
jmp    159f <read_int+0x47f>
lea    0xa96(%rip),%rsi
mov    $0xfffffffd,%edi
call   1040 <msg@plt>
mov    0x29a5(%rip),%rax
mov    (%rax),%edi
call   1030 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"Attempt to read beyond end of file, corrupt file?\0A\00"
@EXIT_FAILURE = global i32 0
define signext i8 @read_int(i8** %0, i64 %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
store i8** %0, i8*** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i8 0, i8* %7
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = load i64, i64* %5
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8*, i8** %6
%14 = icmp ugt i8* %12, %13
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = call i32 @msg(i32 -3, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
store i32 0, i32* %8
br label %20
20: ; preds = %41, %19
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = load i64, i64* %5
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %44
25: ; preds = %20
%26 = load i8**, i8*** %4
%27 = load i8*, i8** %26
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = and i32 %32, 255
%34 = load i32, i32* %8
%35 = mul nsw i32 8, %34
%36 = shl i32 %33, %35
%37 = load i8, i8* %7
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, %36
%40 = trunc i32 %39 to i8
store i8 %40, i8* %7
br label %41
41: ; preds = %25
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %20
44: ; preds = %20
%45 = load i64, i64* %5
%46 = load i8**, i8*** %4
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 %45
store i8* %48, i8** %46
%49 = load i8, i8* %7
ret i8 %49
}

LLVM IR (-O2):
@.str = [51 x i8] c"Attempt to read beyond end of file, corrupt file?\0A\00"
@EXIT_FAILURE = global i32 0
define signext i8 @read_int(i8** nocapture %0, i64 %1, i8* readnone %2) {
%4 = load i8*, i8** %0
%5 = getelementptr inbounds i8, i8* %4, i64 %1
%6 = icmp ugt i8* %5, %2
br i1 %6, label %70, label %7
7: ; preds = %3
%8 = icmp eq i64 %1, 0
br i1 %8, label %87, label %9
9: ; preds = %7
%10 = icmp ult i64 %1, 16
br i1 %10, label %67, label %11
11: ; preds = %9
%12 = and i64 %1, -16
%13 = add i64 %12, -16
%14 = lshr exact i64 %13, 4
%15 = add nuw nsw i64 %14, 1
%16 = and i64 %15, 1
%17 = icmp eq i64 %13, 0
br i1 %17, label %49, label %18
18: ; preds = %11
%19 = and i64 %15, 2305843009213693950
br label %20
20: ; preds = %20, %18
%21 = phi i64 [ 0, %18 ], [ %43, %20 ]
%22 = phi <16 x i8> [ zeroinitializer, %18 ], [ %42, %20 ]
%23 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %18 ], [ %44, %20 ]
%24 = phi i64 [ 0, %18 ], [ %45, %20 ]
%25 = getelementptr inbounds i8, i8* %4, i64 %21
%26 = bitcast i8* %25 to <16 x i8>*
%27 = load <16 x i8>, <16 x i8>* %26
%28 = zext <16 x i8> %27 to <16 x i32>
%29 = shl nsw <16 x i32> %23, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%30 = shl <16 x i32> %28, %29
%31 = trunc <16 x i32> %30 to <16 x i8>
%32 = add <16 x i8> %22, %31
%33 = or i64 %21, 16
%34 = getelementptr inbounds i8, i8* %4, i64 %33
%35 = bitcast i8* %34 to <16 x i8>*
%36 = load <16 x i8>, <16 x i8>* %35
%37 = zext <16 x i8> %36 to <16 x i32>
%38 = shl <16 x i32> %23, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%39 = add <16 x i32> %38, <i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128, i32 128>
%40 = shl <16 x i32> %37, %39
%41 = trunc <16 x i32> %40 to <16 x i8>
%42 = add <16 x i8> %32, %41
%43 = add nuw i64 %21, 32
%44 = add <16 x i32> %23, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%45 = add i64 %24, 2
%46 = icmp eq i64 %45, %19
br i1 %46, label %47, label %20
47: ; preds = %20
%48 = shl <16 x i32> %44, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
br label %49
49: ; preds = %47, %11
%50 = phi <16 x i8> [ undef, %11 ], [ %42, %47 ]
%51 = phi i64 [ 0, %11 ], [ %43, %47 ]
%52 = phi <16 x i8> [ zeroinitializer, %11 ], [ %42, %47 ]
%53 = phi <16 x i32> [ <i32 0, i32 8, i32 16, i32 24, i32 32, i32 40, i32 48, i32 56, i32 64, i32 72, i32 80, i32 88, i32 96, i32 104, i32 112, i32 120>, %11 ], [ %48, %47 ]
%54 = icmp eq i64 %16, 0
br i1 %54, label %63, label %55
55: ; preds = %49
%56 = getelementptr inbounds i8, i8* %4, i64 %51
%57 = bitcast i8* %56 to <16 x i8>*
%58 = load <16 x i8>, <16 x i8>* %57
%59 = zext <16 x i8> %58 to <16 x i32>
%60 = shl <16 x i32> %59, %53
%61 = trunc <16 x i32> %60 to <16 x i8>
%62 = add <16 x i8> %52, %61
br label %63
63: ; preds = %49, %55
%64 = phi <16 x i8> [ %50, %49 ], [ %62, %55 ]
%65 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %64)
%66 = icmp eq i64 %12, %1
br i1 %66, label %87, label %67
67: ; preds = %9, %63
%68 = phi i64 [ 0, %9 ], [ %12, %63 ]
%69 = phi i8 [ 0, %9 ], [ %65, %63 ]
br label %74
70: ; preds = %3
%71 = tail call i32 @msg(i32 -3, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
%73 = tail call i32 @exit(i32 %72)
unreachable
74: ; preds = %67, %74
%75 = phi i64 [ %85, %74 ], [ %68, %67 ]
%76 = phi i8 [ %84, %74 ], [ %69, %67 ]
%77 = getelementptr inbounds i8, i8* %4, i64 %75
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = trunc i64 %75 to i32
%81 = shl nsw i32 %80, 3
%82 = shl i32 %79, %81
%83 = trunc i32 %82 to i8
%84 = add i8 %76, %83
%85 = add nuw nsw i64 %75, 1
%86 = icmp eq i64 %85, %1
br i1 %86, label %87, label %74
87: ; preds = %74, %63, %7
%88 = phi i8 [ 0, %7 ], [ %65, %63 ], [ %84, %74 ]
store i8* %5, i8** %0
ret i8 %88
}