#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 char uint8_t;
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
scalar_t__ endianness();
int /*<<< orphan*/ memcpy(char *, char const *, int);
uint64_t mrtd_bac_get_ssc(const uint8_t *remote_challenge,
                          const uint8_t *rnd_ifd) {
  char ssc[8];
  uint64_t ssc_long;
  memcpy(ssc, remote_challenge + 4, 4);
  memcpy(ssc + 4, rnd_ifd + 4, 4);
  if (endianness()) {
    *(((uint8_t *)(&ssc_long)) + 0) = ssc[0];
    *(((uint8_t *)(&ssc_long)) + 1) = ssc[1];
    *(((uint8_t *)(&ssc_long)) + 2) = ssc[2];
    *(((uint8_t *)(&ssc_long)) + 3) = ssc[3];
    *(((uint8_t *)(&ssc_long)) + 4) = ssc[4];
    *(((uint8_t *)(&ssc_long)) + 5) = ssc[5];
    *(((uint8_t *)(&ssc_long)) + 6) = ssc[6];
    *(((uint8_t *)(&ssc_long)) + 7) = ssc[7];
  } else {
    *(((uint8_t *)(&ssc_long)) + 7) = ssc[0];
    *(((uint8_t *)(&ssc_long)) + 6) = ssc[1];
    *(((uint8_t *)(&ssc_long)) + 5) = ssc[2];
    *(((uint8_t *)(&ssc_long)) + 4) = ssc[3];
    *(((uint8_t *)(&ssc_long)) + 3) = ssc[4];
    *(((uint8_t *)(&ssc_long)) + 2) = ssc[5];
    *(((uint8_t *)(&ssc_long)) + 1) = ssc[6];
    *(((uint8_t *)(&ssc_long)) + 0) = ssc[7];
  }
  return ssc_long;
}


x86 assembly (clang, -O0):
<mrtd_bac_get_ssc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
lea    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    $0x0,%al
call   1040 <endianness@plt>
cmp    $0x0,%rax
je     11a6 <mrtd_bac_get_ssc+0x86>
mov    -0x18(%rbp),%al
mov    %al,-0x1c(%rbp)
mov    -0x17(%rbp),%al
mov    %al,-0x1b(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x14(%rbp),%al
mov    %al,-0x18(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x17(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x16(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x15(%rbp)
jmp    11d6 <mrtd_bac_get_ssc+0xb6>
mov    -0x18(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x17(%rbp),%al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x17(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x18(%rbp)
mov    -0x14(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x13(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x1b(%rbp)
mov    -0x11(%rbp),%al
mov    %al,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrtd_bac_get_ssc>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x4(%rdi),%rsi
lea    0x8(%rsp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
lea    0xc(%rsp),%rdi
add    $0x4,%rbx
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
call   1040 <endianness@plt>
test   %rax,%rax
je     116f <mrtd_bac_get_ssc+0x4f>
mov    0x8(%rsp),%al
mov    0x9(%rsp),%cl
mov    0xa(%rsp),%dl
mov    0xb(%rsp),%bl
jmp    117f <mrtd_bac_get_ssc+0x5f>
mov    0xc(%rsp),%bl
mov    0xd(%rsp),%dl
mov    0xe(%rsp),%cl
mov    0xf(%rsp),%al
movzbl %bl,%esi
shl    $0x18,%esi
movzbl %dl,%edx
shl    $0x10,%edx
or     %esi,%edx
movzbl %cl,%ecx
shl    $0x8,%ecx
or     %edx,%ecx
movzbl %al,%eax
or     %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @mrtd_bac_get_ssc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [8 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 4
%10 = call i32 @memcpy(i8* %7, i8* %9, i32 4)
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds i8, i8* %11, i64 4
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = call i32 @memcpy(i8* %12, i8* %14, i32 4)
%16 = call i64 (...) @endianness()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %51
18: ; preds = %2
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%20 = load i8, i8* %19
%21 = bitcast i32* %6 to i8*
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 %20, i8* %22
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
%24 = load i8, i8* %23
%25 = bitcast i32* %6 to i8*
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %24, i8* %26
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 2
%28 = load i8, i8* %27
%29 = bitcast i32* %6 to i8*
%30 = getelementptr inbounds i8, i8* %29, i64 2
store i8 %28, i8* %30
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 3
%32 = load i8, i8* %31
%33 = bitcast i32* %6 to i8*
%34 = getelementptr inbounds i8, i8* %33, i64 3
store i8 %32, i8* %34
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 4
%36 = load i8, i8* %35
%37 = bitcast i32* %6 to i8*
%38 = getelementptr inbounds i8, i8* %37, i64 4
store i8 %36, i8* %38
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 5
%40 = load i8, i8* %39
%41 = bitcast i32* %6 to i8*
%42 = getelementptr inbounds i8, i8* %41, i64 5
store i8 %40, i8* %42
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 6
%44 = load i8, i8* %43
%45 = bitcast i32* %6 to i8*
%46 = getelementptr inbounds i8, i8* %45, i64 6
store i8 %44, i8* %46
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 7
%48 = load i8, i8* %47
%49 = bitcast i32* %6 to i8*
%50 = getelementptr inbounds i8, i8* %49, i64 7
store i8 %48, i8* %50
br label %84
51: ; preds = %2
%52 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%53 = load i8, i8* %52
%54 = bitcast i32* %6 to i8*
%55 = getelementptr inbounds i8, i8* %54, i64 7
store i8 %53, i8* %55
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 1
%57 = load i8, i8* %56
%58 = bitcast i32* %6 to i8*
%59 = getelementptr inbounds i8, i8* %58, i64 6
store i8 %57, i8* %59
%60 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 2
%61 = load i8, i8* %60
%62 = bitcast i32* %6 to i8*
%63 = getelementptr inbounds i8, i8* %62, i64 5
store i8 %61, i8* %63
%64 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 3
%65 = load i8, i8* %64
%66 = bitcast i32* %6 to i8*
%67 = getelementptr inbounds i8, i8* %66, i64 4
store i8 %65, i8* %67
%68 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 4
%69 = load i8, i8* %68
%70 = bitcast i32* %6 to i8*
%71 = getelementptr inbounds i8, i8* %70, i64 3
store i8 %69, i8* %71
%72 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 5
%73 = load i8, i8* %72
%74 = bitcast i32* %6 to i8*
%75 = getelementptr inbounds i8, i8* %74, i64 2
store i8 %73, i8* %75
%76 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 6
%77 = load i8, i8* %76
%78 = bitcast i32* %6 to i8*
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8 %77, i8* %79
%80 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 7
%81 = load i8, i8* %80
%82 = bitcast i32* %6 to i8*
%83 = getelementptr inbounds i8, i8* %82, i64 0
store i8 %81, i8* %83
br label %84
84: ; preds = %51, %18
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
define i32 @mrtd_bac_get_ssc(i8* %0, i8* %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8, i8* %0, i64 4
%6 = call i32 @memcpy(i8* %4, i8* %5, i32 4)
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%8 = getelementptr inbounds i8, i8* %1, i64 4
%9 = call i32 @memcpy(i8* %7, i8* %8, i32 4)
%10 = call i64 (...) @endianness()
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i8, i8* %4
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%15 = load i8, i8* %14
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%17 = load i8, i8* %16
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%19 = load i8, i8* %18
br label %28
20: ; preds = %2
%21 = load i8, i8* %7
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%23 = load i8, i8* %22
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%25 = load i8, i8* %24
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%27 = load i8, i8* %26
br label %28
28: ; preds = %20, %12
%29 = phi i8 [ %19, %12 ], [ %21, %20 ]
%30 = phi i8 [ %17, %12 ], [ %23, %20 ]
%31 = phi i8 [ %15, %12 ], [ %25, %20 ]
%32 = phi i8 [ %13, %12 ], [ %27, %20 ]
%33 = zext i8 %29 to i32
%34 = shl nuw i32 %33, 24
%35 = zext i8 %30 to i32
%36 = shl nuw nsw i32 %35, 16
%37 = or i32 %36, %34
%38 = zext i8 %31 to i32
%39 = shl nuw nsw i32 %38, 8
%40 = or i32 %37, %39
%41 = zext i8 %32 to i32
%42 = or i32 %40, %41
ret i32 %42
}