#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*/ aout;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
unsigned long aoutsize(char *aout, unsigned long lg) {
  unsigned long gr;
  gr = *(unsigned char *)&(aout[0x04]) + *(unsigned long *)&(aout[0x08]) +
       *(unsigned long *)&(aout[0x0c]);
  if (gr > lg) {
    gr = lg;
    printf("  Wrong a.out table?\n");
  }
  return gr;
}


x86 assembly (clang, -O0):
<aoutsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x8(%rcx),%rax
mov    -0x8(%rbp),%rcx
add    0xc(%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    115e <aoutsize+0x4e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aoutsize>:
push   %rbx
movzbl 0x4(%rdi),%eax
add    0x8(%rdi),%rax
add    0xc(%rdi),%rax
cmp    %rsi,%rax
jbe    1134 <aoutsize+0x24>
mov    %rsi,%rbx
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c" Wrong a.out table?\0A\00"
define i64 @aoutsize(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 4
%8 = load i8, i8* %7
%9 = zext i8 %8 to i64
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 8
%12 = bitcast i8* %11 to i64*
%13 = load i64, i64* %12
%14 = add i64 %9, %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 12
%17 = bitcast i8* %16 to i64*
%18 = load i64, i64* %17
%19 = add i64 %14, %18
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = load i64, i64* %4
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = load i64, i64* %4
store i64 %24, i64* %5
%25 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %2
%27 = load i64, i64* %5
ret i64 %27
}

LLVM IR (-O2):
@str = [21 x i8] c" Wrong a.out table?\00"
define i64 @aoutsize(i8* nocapture %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = load i8, i8* %3
%5 = zext i8 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 8
%7 = bitcast i8* %6 to i64*
%8 = load i64, i64* %7
%9 = add i64 %8, %5
%10 = getelementptr inbounds i8, i8* %0, i64 12
%11 = bitcast i8* %10 to i64*
%12 = load i64, i64* %11
%13 = add i64 %9, %12
%14 = icmp ugt i64 %13, %1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = phi i64 [ %1, %15 ], [ %13, %2 ]
ret i64 %18
}