#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 gmul(unsigned char, int);
void MixColumns(unsigned char state[16]) {
  unsigned char a[4];
  unsigned char c;
  unsigned char i;
  for (i = 0; i < 4; i++) {
    for (c = 0; c < 4; c++) {
      a[c] = state[i * 4 + c];
    }
    state[i * 4] =
        gmul(a[0], 2) ^ gmul(a[3], 1) ^ gmul(a[2], 1) ^ gmul(a[1], 3);
    state[i * 4 + 1] =
        gmul(a[1], 2) ^ gmul(a[0], 1) ^ gmul(a[3], 1) ^ gmul(a[2], 3);
    state[i * 4 + 2] =
        gmul(a[2], 2) ^ gmul(a[1], 1) ^ gmul(a[0], 1) ^ gmul(a[3], 3);
    state[i * 4 + 3] =
        gmul(a[3], 2) ^ gmul(a[2], 1) ^ gmul(a[1], 1) ^ gmul(a[0], 3);
  }
}


x86 assembly (clang, -O0):
<MixColumns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xe(%rbp)
movzbl -0xe(%rbp),%eax
cmp    $0x4,%eax
jge    1354 <MixColumns+0x244>
movb   $0x0,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0x4,%eax
jge    116a <MixColumns+0x5a>
mov    -0x8(%rbp),%rax
movzbl -0xe(%rbp),%ecx
shl    $0x2,%ecx
movzbl -0xd(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movzbl -0xd(%rbp),%eax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
jmp    1131 <MixColumns+0x21>
mov    $0x2,%esi
movzbl -0xc(%rbp),%edi
call   1030 <gmul@plt>
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
mov    $0x1,%esi
movzbl -0x9(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x40(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x1,%esi
movzbl -0xa(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x3c(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    $0x3,%esi
movzbl -0xb(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x38(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0xe(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    $0x2,%esi
movzbl -0xb(%rbp),%edi
call   1030 <gmul@plt>
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    $0x1,%esi
movzbl -0xc(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x34(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    $0x1,%esi
movzbl -0x9(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x30(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    $0x3,%esi
movzbl -0xa(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x2c(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0xe(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    $0x2,%esi
movzbl -0xa(%rbp),%edi
call   1030 <gmul@plt>
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
mov    $0x1,%esi
movzbl -0xb(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x28(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    $0x1,%esi
movzbl -0xc(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    $0x3,%esi
movzbl -0x9(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0xe(%rbp),%ecx
shl    $0x2,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    $0x2,%esi
movzbl -0x9(%rbp),%edi
call   1030 <gmul@plt>
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1,%esi
movzbl -0xa(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x1c(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0x1,%esi
movzbl -0xb(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x3,%esi
movzbl -0xc(%rbp),%edi
call   1030 <gmul@plt>
mov    %al,%cl
mov    -0x14(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0xe(%rbp),%ecx
shl    $0x2,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xe(%rbp),%al
add    $0x1,%al
mov    %al,-0xe(%rbp)
jmp    1120 <MixColumns+0x10>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MixColumns>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
movzbl (%rax,%r15,4),%edi
mov    %edi,(%rsp)
movzbl 0x1(%rax,%r15,4),%r12d
movzbl 0x2(%rax,%r15,4),%r13d
movzbl 0x3(%rax,%r15,4),%ebp
mov    %ebp,0x4(%rsp)
mov    $0x2,%esi
call   1030 <gmul@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
xor    %bl,%r14b
mov    %r13d,%edi
mov    %r13d,%ebp
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%ebx
mov    %r12d,0x10(%rsp)
mov    %r12d,%edi
mov    $0x3,%esi
call   1030 <gmul@plt>
xor    %bl,%al
xor    %r14b,%al
mov    0x8(%rsp),%r13
mov    %al,0x0(%r13,%r15,4)
mov    %r12d,%edi
mov    $0x2,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    (%rsp),%r12d
mov    %r12d,%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%ebx
xor    %r14b,%bl
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    %ebp,0x14(%rsp)
mov    %ebp,%edi
mov    $0x3,%esi
call   1030 <gmul@plt>
xor    %r14b,%al
xor    %bl,%al
mov    %al,0x1(%r13,%r15,4)
mov    %ebp,%edi
mov    $0x2,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    0x10(%rsp),%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%ebx
xor    %r14b,%bl
mov    %r12d,%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    0x4(%rsp),%r13d
mov    %r13d,%edi
mov    $0x3,%esi
call   1030 <gmul@plt>
xor    %r14b,%al
xor    %bl,%al
mov    0x8(%rsp),%r12
mov    %al,0x2(%r12,%r15,4)
mov    %r13d,%edi
mov    $0x2,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    0x14(%rsp),%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%ebx
xor    %r14b,%bl
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <gmul@plt>
mov    %eax,%r14d
mov    (%rsp),%edi
mov    $0x3,%esi
call   1030 <gmul@plt>
xor    %r14b,%al
xor    %bl,%al
mov    %al,0x3(%r12,%r15,4)
add    $0x1,%r15
cmp    $0x4,%r15
jne    1130 <MixColumns+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MixColumns(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8]
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %5
br label %6
6: ; preds = %140, %1
%7 = load i8, i8* %5
%8 = zext i8 %7 to i32
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %143
10: ; preds = %6
store i8 0, i8* %4
br label %11
11: ; preds = %29, %10
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i8, i8* %5
%18 = zext i8 %17 to i32
%19 = mul nsw i32 %18, 4
%20 = load i8, i8* %4
%21 = zext i8 %20 to i32
%22 = add nsw i32 %19, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %16, i64 %23
%25 = load i8, i8* %24
%26 = load i8, i8* %4
%27 = zext i8 %26 to i64
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %15
%30 = load i8, i8* %4
%31 = add i8 %30, 1
store i8 %31, i8* %4
br label %11
32: ; preds = %11
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%34 = load i8, i8* %33
%35 = call zeroext i8 @gmul(i8 zeroext %34, i32 2)
%36 = zext i8 %35 to i32
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%38 = load i8, i8* %37
%39 = call zeroext i8 @gmul(i8 zeroext %38, i32 1)
%40 = zext i8 %39 to i32
%41 = xor i32 %36, %40
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%43 = load i8, i8* %42
%44 = call zeroext i8 @gmul(i8 zeroext %43, i32 1)
%45 = zext i8 %44 to i32
%46 = xor i32 %41, %45
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%48 = load i8, i8* %47
%49 = call zeroext i8 @gmul(i8 zeroext %48, i32 3)
%50 = zext i8 %49 to i32
%51 = xor i32 %46, %50
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %2
%54 = load i8, i8* %5
%55 = zext i8 %54 to i32
%56 = mul nsw i32 %55, 4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %53, i64 %57
store i8 %52, i8* %58
%59 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%60 = load i8, i8* %59
%61 = call zeroext i8 @gmul(i8 zeroext %60, i32 2)
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%64 = load i8, i8* %63
%65 = call zeroext i8 @gmul(i8 zeroext %64, i32 1)
%66 = zext i8 %65 to i32
%67 = xor i32 %62, %66
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%69 = load i8, i8* %68
%70 = call zeroext i8 @gmul(i8 zeroext %69, i32 1)
%71 = zext i8 %70 to i32
%72 = xor i32 %67, %71
%73 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%74 = load i8, i8* %73
%75 = call zeroext i8 @gmul(i8 zeroext %74, i32 3)
%76 = zext i8 %75 to i32
%77 = xor i32 %72, %76
%78 = trunc i32 %77 to i8
%79 = load i8*, i8** %2
%80 = load i8, i8* %5
%81 = zext i8 %80 to i32
%82 = mul nsw i32 %81, 4
%83 = add nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %79, i64 %84
store i8 %78, i8* %85
%86 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%87 = load i8, i8* %86
%88 = call zeroext i8 @gmul(i8 zeroext %87, i32 2)
%89 = zext i8 %88 to i32
%90 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%91 = load i8, i8* %90
%92 = call zeroext i8 @gmul(i8 zeroext %91, i32 1)
%93 = zext i8 %92 to i32
%94 = xor i32 %89, %93
%95 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%96 = load i8, i8* %95
%97 = call zeroext i8 @gmul(i8 zeroext %96, i32 1)
%98 = zext i8 %97 to i32
%99 = xor i32 %94, %98
%100 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%101 = load i8, i8* %100
%102 = call zeroext i8 @gmul(i8 zeroext %101, i32 3)
%103 = zext i8 %102 to i32
%104 = xor i32 %99, %103
%105 = trunc i32 %104 to i8
%106 = load i8*, i8** %2
%107 = load i8, i8* %5
%108 = zext i8 %107 to i32
%109 = mul nsw i32 %108, 4
%110 = add nsw i32 %109, 2
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %106, i64 %111
store i8 %105, i8* %112
%113 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%114 = load i8, i8* %113
%115 = call zeroext i8 @gmul(i8 zeroext %114, i32 2)
%116 = zext i8 %115 to i32
%117 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%118 = load i8, i8* %117
%119 = call zeroext i8 @gmul(i8 zeroext %118, i32 1)
%120 = zext i8 %119 to i32
%121 = xor i32 %116, %120
%122 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%123 = load i8, i8* %122
%124 = call zeroext i8 @gmul(i8 zeroext %123, i32 1)
%125 = zext i8 %124 to i32
%126 = xor i32 %121, %125
%127 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%128 = load i8, i8* %127
%129 = call zeroext i8 @gmul(i8 zeroext %128, i32 3)
%130 = zext i8 %129 to i32
%131 = xor i32 %126, %130
%132 = trunc i32 %131 to i8
%133 = load i8*, i8** %2
%134 = load i8, i8* %5
%135 = zext i8 %134 to i32
%136 = mul nsw i32 %135, 4
%137 = add nsw i32 %136, 3
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %133, i64 %138
store i8 %132, i8* %139
br label %140
140: ; preds = %32
%141 = load i8, i8* %5
%142 = add i8 %141, 1
store i8 %142, i8* %5
br label %6
143: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @MixColumns(i8* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %47, %2 ]
%4 = shl nuw nsw i64 %3, 2
%5 = getelementptr i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = load i8, i8* %7
%9 = getelementptr inbounds i8, i8* %5, i64 2
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %5, i64 3
%12 = load i8, i8* %11
%13 = tail call zeroext i8 @gmul(i8 zeroext %6, i32 2)
%14 = tail call zeroext i8 @gmul(i8 zeroext %12, i32 1)
%15 = xor i8 %14, %13
%16 = tail call zeroext i8 @gmul(i8 zeroext %10, i32 1)
%17 = xor i8 %15, %16
%18 = tail call zeroext i8 @gmul(i8 zeroext %8, i32 3)
%19 = xor i8 %17, %18
store i8 %19, i8* %5
%20 = tail call zeroext i8 @gmul(i8 zeroext %8, i32 2)
%21 = tail call zeroext i8 @gmul(i8 zeroext %6, i32 1)
%22 = xor i8 %21, %20
%23 = tail call zeroext i8 @gmul(i8 zeroext %12, i32 1)
%24 = xor i8 %22, %23
%25 = tail call zeroext i8 @gmul(i8 zeroext %10, i32 3)
%26 = xor i8 %24, %25
%27 = or i64 %4, 1
%28 = getelementptr inbounds i8, i8* %0, i64 %27
store i8 %26, i8* %28
%29 = tail call zeroext i8 @gmul(i8 zeroext %10, i32 2)
%30 = tail call zeroext i8 @gmul(i8 zeroext %8, i32 1)
%31 = xor i8 %30, %29
%32 = tail call zeroext i8 @gmul(i8 zeroext %6, i32 1)
%33 = xor i8 %31, %32
%34 = tail call zeroext i8 @gmul(i8 zeroext %12, i32 3)
%35 = xor i8 %33, %34
%36 = or i64 %4, 2
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 %35, i8* %37
%38 = tail call zeroext i8 @gmul(i8 zeroext %12, i32 2)
%39 = tail call zeroext i8 @gmul(i8 zeroext %10, i32 1)
%40 = xor i8 %39, %38
%41 = tail call zeroext i8 @gmul(i8 zeroext %8, i32 1)
%42 = xor i8 %40, %41
%43 = tail call zeroext i8 @gmul(i8 zeroext %6, i32 3)
%44 = xor i8 %42, %43
%45 = or i64 %4, 3
%46 = getelementptr inbounds i8, i8* %0, i64 %45
store i8 %44, i8* %46
%47 = add nuw nsw i64 %3, 1
%48 = icmp eq i64 %47, 4
br i1 %48, label %49, label %2
49: ; preds = %2
ret void
}