#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 __m128i;

/* Variables and functions */
int _mm_aesenc_si128(int, int const);
int _mm_aesenclast_si128(int, int const);
__m128i aesni_enc(int rounds, const __m128i *keysched, const __m128i from) {
  __m128i tmp;
  int i;
  tmp = from ^ keysched[0];
  for (i = 0; i < rounds; i++)
    tmp = _mm_aesenc_si128(tmp, keysched[i + 1]);
  return _mm_aesenclast_si128(tmp, keysched[i + 1]);
}


x86 assembly (clang, -O0):
<aesni_enc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
xor    (%rcx),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117a <aesni_enc+0x5a>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <_mm_aesenc_si128@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <aesni_enc+0x25>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <_mm_aesenclast_si128@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aesni_enc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%eax
mov    %rsi,%r15
xor    (%rsi),%eax
test   %edi,%edi
jle    115b <aesni_enc+0x3b>
mov    %edi,%r14d
mov    %edi,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x4(%r15,%rbx,4),%esi
add    $0x1,%rbx
mov    %eax,%edi
call   1040 <_mm_aesenc_si128@plt>
cmp    %rbx,%r12
jne    1140 <aesni_enc+0x20>
add    $0x1,%r14d
jmp    1161 <aesni_enc+0x41>
mov    $0x1,%r14d
mov    (%r15,%r14,4),%esi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <_mm_aesenclast_si128@plt>

LLVM IR (-O0):
define i32 @aesni_enc(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = load i32*, i32** %5
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = xor i32 %9, %12
store i32 %13, i32* %7
store i32 0, i32* %8
br label %14
14: ; preds = %27, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i32, i32* %7
%20 = load i32*, i32** %5
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @_mm_aesenc_si128(i32 %19, i32 %25)
store i32 %26, i32* %7
br label %27
27: ; preds = %18
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %14
30: ; preds = %14
%31 = load i32, i32* %7
%32 = load i32*, i32** %5
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %32, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @_mm_aesenclast_si128(i32 %31, i32 %37)
ret i32 %38
}

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