#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*/ print(int /*<<< orphan*/ *, int);
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_encrypt(void *plaintext, void const *key) {
  uint32_t round_key[32] = {0};
  sm4_key_schedule(key, round_key);
  print(round_key, 32);
  int i;
  for (i = 0; i < 32; ++i)
    sm4_round_func((uint32_t *)plaintext, round_key[i]);
  sm4_reverse((uint32_t *)plaintext);
}


x86 assembly (clang, -O0):
<sm4_encrypt>:
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   1070 <sm4_key_schedule@plt>
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1040 <print@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    11d9 <sm4_encrypt+0x89>
mov    -0x8(%rbp),%rdi
movslq -0x94(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
call   1050 <sm4_round_func@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11a1 <sm4_encrypt+0x51>
mov    -0x8(%rbp),%rdi
call   1060 <sm4_reverse@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sm4_encrypt>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r15
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,%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1060 <sm4_key_schedule@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   1030 <print@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%esi
mov    %r15,%rdi
call   1040 <sm4_round_func@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    11a0 <sm4_encrypt+0x60>
mov    %r15,%rdi
call   1050 <sm4_reverse@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sm4_encrypt(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)
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%12 = call i32 @print(i32* %11, i32 32)
store i32 0, i32* %6
br label %13
13: ; preds = %24, %2
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @sm4_round_func(i32* %18, i32 %22)
br label %24
24: ; preds = %16
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %13
27: ; preds = %13
%28 = load i8*, i8** %3
%29 = bitcast i8* %28 to i32*
%30 = call i32 @sm4_reverse(i32* %29)
ret void
}

LLVM IR (-O2):
define void @sm4_encrypt(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 = call i32 @print(i32* %5, i32 32)
%8 = bitcast i8* %0 to i32*
br label %9
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %14, %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* %8, i32 %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, 32
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = call i32 @sm4_reverse(i32* %8)
ret void
}