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

/* Variables and functions */
int32_t unpack_int32(const char *target, int swap_endian) {
  if (swap_endian) {
    char buffer[4] = {target[3], target[2], target[1], target[0]};
    return *(int32_t *)(buffer);
  } else {
    return *(int32_t *)(target);
  }
}


x86 assembly (clang, -O0):
<unpack_int32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1147 <unpack_int32+0x47>
mov    -0x10(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x17(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x16(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1150 <unpack_int32+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_int32>:
test   %esi,%esi
je     1109 <unpack_int32+0x9>
mov    (%rdi),%eax
bswap  %eax
ret
mov    (%rdi),%eax
ret

LLVM IR (-O0):
define i32 @unpack_int32(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %2
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 3
%13 = load i8, i8* %12
store i8 %13, i8* %10
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8, i8* %16
store i8 %17, i8* %14
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
store i8 %21, i8* %18
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
store i8 %25, i8* %22
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
store i32 %28, i32* %3
br label %33
29: ; preds = %2
%30 = load i8*, i8** %4
%31 = bitcast i8* %30 to i32*
%32 = load i32, i32* %31
store i32 %32, i32* %3
br label %33
33: ; preds = %29, %9
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @unpack_int32(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 3
%6 = load i8, i8* %5
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = load i8, i8* %7
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = load i8, i8* %0
%12 = zext i8 %11 to i32
%13 = shl nuw i32 %12, 24
%14 = zext i8 %10 to i32
%15 = shl nuw nsw i32 %14, 16
%16 = zext i8 %8 to i32
%17 = shl nuw nsw i32 %16, 8
%18 = zext i8 %6 to i32
%19 = or i32 %17, %18
%20 = or i32 %19, %15
%21 = or i32 %20, %13
br label %25
22: ; preds = %2
%23 = bitcast i8* %0 to i32*
%24 = load i32, i32* %23
br label %25
25: ; preds = %22, %4
%26 = phi i32 [ %21, %4 ], [ %24, %22 ]
ret i32 %26
}