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

/* Variables and functions */
int /*<<< orphan*/ sm4_key_schedule(void const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sm4_reverse(int /*<<< orphan*/ *);
int /*<<< orphan*/ sm4_round_func(int /*<<< orphan*/ *, int /*<<< orphan*/);
void sm4_decrypt(void *ciphertext, void const *key) {
  uint32_t round_key[32] = {0};
  sm4_key_schedule(key, round_key);
  int i;
  for (i = 0; i < 32; ++i)
    sm4_round_func((uint32_t *)ciphertext, round_key[31 - i]);
  sm4_reverse((uint32_t *)ciphertext);
}


x86 assembly (clang, -O0):
<sm4_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1060 <sm4_key_schedule@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    11be <sm4_decrypt+0x7e>
mov    -0x8(%rbp),%rdi
mov    $0x1f,%eax
sub    -0x94(%rbp),%eax
cltq
mov    -0x90(%rbp,%rax,4),%esi
call   1040 <sm4_round_func@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1180 <sm4_decrypt+0x40>
mov    -0x8(%rbp),%rdi
call   1050 <sm4_reverse@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sm4_decrypt>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <sm4_key_schedule@plt>
mov    $0x1f,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <sm4_round_func@plt>
add    $0xffffffffffffffff,%rbx
jb     1180 <sm4_decrypt+0x50>
mov    %r14,%rdi
call   1040 <sm4_reverse@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @sm4_decrypt(i8* %0, i8* %1) {
%3 = alloca [32 x i32]
%4 = bitcast [32 x i32]* %3 to i8*
%5 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%6 = call i32 @sm4_key_schedule(i8* %1, i32* %5)
%7 = bitcast i8* %0 to i32*
br label %8
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %14, %8 ]
%10 = sub nuw nsw i64 31, %9
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @sm4_round_func(i32* %7, i32 %12)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, 32
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = call i32 @sm4_reverse(i32* %7)
ret void
}