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

/* Variables and functions */
int check_byte_ending(void) {
  char buffer[4] = {1, 2, 3, 4};
  void *vptr = buffer;
  u_int32_t *iptr = (u_int32_t *)buffer;
  int i, bsum, lsum;
  vptr += 3;
  if (*((char *)vptr) != buffer[3])
    return 0;
  for (i = bsum = lsum = 0; i < 4; i++) {
    bsum = (bsum * 256) + buffer[i];
    lsum = (lsum * 256) + buffer[3 - i];
  }
  if (bsum == *iptr) {
    return 1;
  } else if (lsum == *iptr) {
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<check_byte_ending>:
push   %rbp
mov    %rsp,%rbp
mov    0xef6(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
je     1148 <check_byte_ending+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11e1 <check_byte_ending+0xe1>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11a4 <check_byte_ending+0xa4>
mov    -0x20(%rbp),%eax
shl    $0x8,%eax
movslq -0x1c(%rbp),%rcx
movsbl -0x8(%rbp,%rcx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x8,%eax
mov    $0x3,%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsbl -0x8(%rbp,%rcx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <check_byte_ending+0x5d>
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    11bf <check_byte_ending+0xbf>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <check_byte_ending+0xe1>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    11da <check_byte_ending+0xda>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <check_byte_ending+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_byte_ending>:
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
@__const.check_byte_ending.buffer = [4 x i8] c"\01\02\03\04"
define i32 @check_byte_ending() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [4 x i8]* %2 to i8*
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
store i8* %9, i8** %3
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %4
%12 = load i8*, i8** %3
%13 = getelementptr i8, i8* %12, i64 3
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %16, %19
br i1 %20, label %21, label %22
21: ; preds = %0
store i32 0, i32* %1
br label %60
22: ; preds = %0
store i32 0, i32* %7
store i32 0, i32* %6
store i32 0, i32* %5
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %47
26: ; preds = %23
%27 = load i32, i32* %6
%28 = mul nsw i32 %27, 256
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add nsw i32 %28, %33
store i32 %34, i32* %6
%35 = load i32, i32* %7
%36 = mul nsw i32 %35, 256
%37 = load i32, i32* %5
%38 = sub nsw i32 3, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = add nsw i32 %36, %42
store i32 %43, i32* %7
br label %44
44: ; preds = %26
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %23
47: ; preds = %23
%48 = load i32, i32* %6
%49 = load i32*, i32** %4
%50 = load i32, i32* %49
%51 = icmp eq i32 %48, %50
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 1, i32* %1
br label %60
53: ; preds = %47
%54 = load i32, i32* %7
%55 = load i32*, i32** %4
%56 = load i32, i32* %55
%57 = icmp eq i32 %54, %56
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 -1, i32* %1
br label %60
59: ; preds = %53
store i32 0, i32* %1
br label %60
60: ; preds = %59, %58, %52, %21
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
define i32 @check_byte_ending() {
ret i32 -1
}