#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 char sm4Sbox(unsigned char);
unsigned long sm4Lt(unsigned long ka) {
  unsigned long bb = 0;
  unsigned long c = 0;
  unsigned char a[4];
  unsigned char b[4];
  {
    (a)[(0)] = (unsigned char)((ka) >> 24);
    (a)[(0) + 1] = (unsigned char)((ka) >> 16);
    (a)[(0) + 2] = (unsigned char)((ka) >> 8);
    (a)[(0) + 3] = (unsigned char)((ka));
  }
  b[0] = sm4Sbox(a[0]);
  b[1] = sm4Sbox(a[1]);
  b[2] = sm4Sbox(a[2]);
  b[3] = sm4Sbox(a[3]);
  {
    (bb) = ((unsigned long)(b)[(0)] << 24) |
           ((unsigned long)(b)[(0) + 1] << 16) |
           ((unsigned long)(b)[(0) + 2] << 8) | ((unsigned long)(b)[(0) + 3]);
  }
  c = bb ^ ((((((bb)) & 0xFFFFFFFF) << 2) | ((bb) >> (32 - 2)))) ^
      ((((((bb)) & 0xFFFFFFFF) << 10) | ((bb) >> (32 - 10)))) ^
      ((((((bb)) & 0xFFFFFFFF) << 18) | ((bb) >> (32 - 18)))) ^
      ((((((bb)) & 0xFFFFFFFF) << 24) | ((bb) >> (32 - 24))));
  return c;
}


x86 assembly (clang, -O0):
<sm4Lt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x18,%rax
mov    %al,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
mov    %al,-0x1b(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
mov    %al,-0x1a(%rbp)
mov    -0x8(%rbp),%rax
mov    %al,-0x19(%rbp)
movzbl -0x1c(%rbp),%edi
call   1030 <sm4Sbox@plt>
mov    %al,-0x20(%rbp)
movzbl -0x1b(%rbp),%edi
call   1030 <sm4Sbox@plt>
mov    %al,-0x1f(%rbp)
movzbl -0x1a(%rbp),%edi
call   1030 <sm4Sbox@plt>
mov    %al,-0x1e(%rbp)
movzbl -0x19(%rbp),%edi
call   1030 <sm4Sbox@plt>
mov    %al,-0x1d(%rbp)
movzbl -0x20(%rbp),%eax
shl    $0x18,%rax
movzbl -0x1f(%rbp),%ecx
shl    $0x10,%rcx
or     %rcx,%rax
movzbl -0x1e(%rbp),%ecx
shl    $0x8,%rcx
or     %rcx,%rax
movzbl -0x1d(%rbp),%ecx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movabs $0xffffffff,%rcx
and    -0x10(%rbp),%rcx
shl    $0x2,%rcx
mov    -0x10(%rbp),%rdx
shr    $0x1e,%rdx
or     %rdx,%rcx
xor    %rcx,%rax
movabs $0xffffffff,%rcx
and    -0x10(%rbp),%rcx
shl    $0xa,%rcx
mov    -0x10(%rbp),%rdx
shr    $0x16,%rdx
or     %rdx,%rcx
xor    %rcx,%rax
movabs $0xffffffff,%rcx
and    -0x10(%rbp),%rcx
shl    $0x12,%rcx
mov    -0x10(%rbp),%rdx
shr    $0xe,%rdx
or     %rdx,%rcx
xor    %rcx,%rax
movabs $0xffffffff,%rcx
and    -0x10(%rbp),%rcx
shl    $0x18,%rcx
mov    -0x10(%rbp),%rdx
shr    $0x8,%rdx
or     %rdx,%rcx
xor    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sm4Lt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %ebx,%eax
shr    $0x18,%eax
mov    %eax,%edi
call   1030 <sm4Sbox@plt>
mov    %eax,%ebp
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
call   1030 <sm4Sbox@plt>
mov    %eax,%r14d
movzbl %bh,%edi
call   1030 <sm4Sbox@plt>
mov    %eax,%r15d
movzbl %bl,%edi
call   1030 <sm4Sbox@plt>
mov    %eax,%ecx
movzbl %bpl,%esi
mov    %rsi,%rax
shl    $0x18,%rax
movzbl %r14b,%edx
shl    $0x10,%rdx
or     %rax,%rdx
movzbl %r15b,%eax
shl    $0x8,%rax
or     %rdx,%rax
movzbl %cl,%ecx
or     %rax,%rcx
shr    $0x6,%rsi
lea    (%rsi,%rcx,4),%rsi
xor    %rcx,%rsi
mov    %rcx,%rdi
shl    $0xa,%rdi
shr    $0x16,%rdx
or     %rdi,%rdx
xor    %rsi,%rdx
mov    %rcx,%rsi
shl    $0x12,%rsi
mov    %rax,%rdi
shr    $0xe,%rdi
or     %rsi,%rdi
shl    $0x18,%rcx
shr    $0x8,%rax
or     %rcx,%rax
xor    %rdi,%rax
xor    %rdx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @sm4Lt(i64 %0) {
%2 = lshr i64 %0, 24
%3 = trunc i64 %2 to i8
%4 = lshr i64 %0, 16
%5 = trunc i64 %4 to i8
%6 = lshr i64 %0, 8
%7 = trunc i64 %6 to i8
%8 = trunc i64 %0 to i8
%9 = tail call zeroext i8 @sm4Sbox(i8 zeroext %3)
%10 = tail call zeroext i8 @sm4Sbox(i8 zeroext %5)
%11 = tail call zeroext i8 @sm4Sbox(i8 zeroext %7)
%12 = tail call zeroext i8 @sm4Sbox(i8 zeroext %8)
%13 = zext i8 %9 to i64
%14 = shl nuw nsw i64 %13, 24
%15 = zext i8 %10 to i64
%16 = shl nuw nsw i64 %15, 16
%17 = or i64 %16, %14
%18 = zext i8 %11 to i64
%19 = shl nuw nsw i64 %18, 8
%20 = or i64 %17, %19
%21 = zext i8 %12 to i64
%22 = or i64 %20, %21
%23 = shl nuw nsw i64 %22, 2
%24 = lshr i64 %13, 6
%25 = or i64 %23, %24
%26 = xor i64 %25, %22
%27 = shl nuw nsw i64 %22, 10
%28 = lshr i64 %17, 22
%29 = or i64 %27, %28
%30 = xor i64 %26, %29
%31 = shl nuw nsw i64 %22, 18
%32 = lshr i64 %20, 14
%33 = or i64 %31, %32
%34 = xor i64 %30, %33
%35 = shl nuw nsw i64 %22, 24
%36 = lshr exact i64 %20, 8
%37 = or i64 %35, %36
%38 = xor i64 %34, %37
ret i64 %38
}