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

/* Variables and functions */
scalar_t__ Endian_invariant(unsigned long *, int);
int /*<<< orphan*/ passfail(int, char *, int, char *);
void test_Endian() {
  struct {
    unsigned long wide;
    char *thin;
  } d = {0x64636261, "abcd"};
  for (int i = 0; i < 4; ++i) {
    char c = *(char *)Endian_invariant(&d.wide, i);
    passfail(c == d.thin[i],
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/jlettvin/Unicode/refs/heads/master/c/"
             "test_Endian.c",
             18, "Endian invariant byte indexing");
  }
}


x86 assembly (clang, -O0):
<test_Endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ce1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2cde(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11a0 <test_Endian+0x80>
lea    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <Endian_invariant@plt>
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe84(%rip),%rsi
mov    $0x12,%edx
lea    0xf05(%rip),%rcx
call   1030 <passfail@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <test_Endian+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_Endian>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movups 0x2ce0(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <Endian_invariant@plt>
mov    (%rax),%al
mov    0x8(%rsp),%rcx
xor    %edi,%edi
cmp    (%rcx),%al
sete   %dil
lea    0xeae(%rip),%rbx
lea    0xf34(%rip),%r14
mov    %rbx,%rsi
mov    $0x12,%edx
mov    %r14,%rcx
call   1030 <passfail@plt>
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <Endian_invariant@plt>
mov    (%rax),%al
mov    0x8(%rsp),%rcx
xor    %edi,%edi
cmp    0x1(%rcx),%al
sete   %dil
mov    %rbx,%rsi
mov    $0x12,%edx
mov    %r14,%rcx
call   1030 <passfail@plt>
mov    %r15,%rdi
mov    $0x2,%esi
call   1040 <Endian_invariant@plt>
mov    (%rax),%al
mov    0x8(%rsp),%rcx
xor    %edi,%edi
cmp    0x2(%rcx),%al
sete   %dil
mov    %rbx,%rsi
mov    $0x12,%edx
mov    %r14,%rcx
call   1030 <passfail@plt>
mov    %r15,%rdi
mov    $0x3,%esi
call   1040 <Endian_invariant@plt>
mov    (%rax),%al
mov    0x8(%rsp),%rcx
xor    %edi,%edi
cmp    0x3(%rcx),%al
sete   %dil
mov    %rbx,%rsi
mov    $0x12,%edx
mov    %r14,%rcx
call   1030 <passfail@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.anon = type { i64, i8* }
@.str = [5 x i8] c"abcd\00"
@__const.test_Endian.d = %struct.anon { i64 1684234849, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0) }
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jlettvin/Unicode/refs/heads/master/c/test_Endian.c\00"
@.str.2 = [31 x i8] c"Endian invariant byte indexing\00"
define void @test_Endian() {
%1 = alloca %struct.anon
%2 = alloca i32
%3 = alloca i8
%4 = bitcast %struct.anon* %1 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%10 = load i32, i32* %2
%11 = call i64 @Endian_invariant(i64* %9, i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i8, i8* %12
store i8 %13, i8* %3
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%17 = load i8*, i8** %16
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %15, %22
%24 = zext i1 %23 to i32
%25 = call i32 @passfail(i32 %24, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %8
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %5
29: ; preds = %5
ret void
}

LLVM IR (-O2):
%struct.anon = type { i64, i8* }
@.str = [5 x i8] c"abcd\00"
@__const.test_Endian.d = %struct.anon { i64 1684234849, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0) }
@.str.1 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jlettvin/Unicode/refs/heads/master/c/test_Endian.c\00"
@.str.2 = [31 x i8] c"Endian invariant byte indexing\00"
define void @test_Endian() {
%1 = alloca %struct.anon
%2 = bitcast %struct.anon* %1 to i8*
%3 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0
%4 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
%5 = call i64 @Endian_invariant(i64* %3, i32 0)
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %6
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp eq i8 %7, %9
%11 = zext i1 %10 to i32
%12 = call i32 @passfail(i32 %11, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @Endian_invariant(i64* %3, i32 1)
%14 = inttoptr i64 %13 to i8*
%15 = load i8, i8* %14
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %15, %18
%20 = zext i1 %19 to i32
%21 = call i32 @passfail(i32 %20, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%22 = call i64 @Endian_invariant(i64* %3, i32 2)
%23 = inttoptr i64 %22 to i8*
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = icmp eq i8 %24, %27
%29 = zext i1 %28 to i32
%30 = call i32 @passfail(i32 %29, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%31 = call i64 @Endian_invariant(i64* %3, i32 3)
%32 = inttoptr i64 %31 to i8*
%33 = load i8, i8* %32
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = load i8, i8* %35
%37 = icmp eq i8 %33, %36
%38 = zext i1 %37 to i32
%39 = call i32 @passfail(i32 %38, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
ret void
}