#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 */
unsigned short toUInt16(unsigned char, unsigned char);
unsigned int toUInt32(unsigned short, unsigned short);
unsigned int bytesToUInt(unsigned char *arr) {
  unsigned char charA = (unsigned char)*arr;
  unsigned char charB = (unsigned char)*(arr + 1);
  unsigned char charC = (unsigned char)*(arr + 2);
  unsigned char charD = (unsigned char)*(arr + 3);
  unsigned short shortA = toUInt16(charA, charB);
  unsigned short shortB = toUInt16(charC, charD);
  return toUInt32(shortA, shortB);
}


x86 assembly (clang, -O0):
<bytesToUInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0xc(%rbp)
mov    -0x9(%rbp),%al
movzbl %al,%edi
movzbl -0xa(%rbp),%esi
call   1040 <toUInt16@plt>
mov    %ax,-0xe(%rbp)
mov    -0xb(%rbp),%al
movzbl %al,%edi
movzbl -0xc(%rbp),%esi
call   1040 <toUInt16@plt>
mov    %ax,-0x10(%rbp)
mov    -0xe(%rbp),%ax
movzwl %ax,%edi
movzwl -0x10(%rbp),%esi
call   1030 <toUInt32@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytesToUInt>:
push   %rbp
push   %r14
push   %rbx
movzbl (%rdi),%eax
movzbl 0x1(%rdi),%esi
movzbl 0x2(%rdi),%r14d
movzbl 0x3(%rdi),%ebp
mov    %eax,%edi
call   1040 <toUInt16@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <toUInt16@plt>
movzwl %bx,%edi
movzwl %ax,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <toUInt32@plt>

LLVM IR (-O0):
define i32 @bytesToUInt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
store i8 %10, i8* %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
store i8 %13, i8* %4
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = load i8, i8* %18
store i8 %19, i8* %6
%20 = load i8, i8* %3
%21 = load i8, i8* %4
%22 = call zeroext i16 @toUInt16(i8 zeroext %20, i8 zeroext %21)
store i16 %22, i16* %7
%23 = load i8, i8* %5
%24 = load i8, i8* %6
%25 = call zeroext i16 @toUInt16(i8 zeroext %23, i8 zeroext %24)
store i16 %25, i16* %8
%26 = load i16, i16* %7
%27 = load i16, i16* %8
%28 = call i32 @toUInt32(i16 zeroext %26, i16 zeroext %27)
ret i32 %28
}

LLVM IR (-O2):
define i32 @bytesToUInt(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = load i8, i8* %5
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = load i8, i8* %7
%9 = tail call zeroext i16 @toUInt16(i8 zeroext %2, i8 zeroext %4)
%10 = tail call zeroext i16 @toUInt16(i8 zeroext %6, i8 zeroext %8)
%11 = tail call i32 @toUInt32(i16 zeroext %9, i16 zeroext %10)
ret i32 %11
}