#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 */
int /*<<< orphan*/ poly1305_add(unsigned char *, unsigned char const *);
void poly1305_freeze(unsigned char h[17]) {
  static const unsigned char minusp[17] = {0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
                                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                           0x00, 0x00, 0x00, 0x00, 0xfc};
  unsigned char horig[17], negative;
  unsigned int i;
  for (i = 0; i < 17; i++)
    horig[i] = h[i];
  poly1305_add(h, minusp);
  negative = -(h[16] >> 7);
  for (i = 0; i < 17; i++)
    h[i] ^= negative & (horig[i] ^ h[i]);
}


x86 assembly (clang, -O0):
<poly1305_freeze>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x11,-0x28(%rbp)
jae    114c <poly1305_freeze+0x3c>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%eax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1123 <poly1305_freeze+0x13>
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <poly1305_add@plt>
mov    -0x8(%rbp),%rax
movzbl 0x10(%rax),%ecx
sar    $0x7,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %al,-0x21(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x11,-0x28(%rbp)
jae    11b8 <poly1305_freeze+0xa8>
movzbl -0x21(%rbp),%esi
mov    -0x28(%rbp),%eax
movzbl -0x20(%rbp,%rax,1),%eax
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%edx
movzbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
and    %eax,%esi
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
xor    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1175 <poly1305_freeze+0x65>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly1305_freeze>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movups (%rdi),%xmm0
movaps %xmm0,(%rsp)
movzbl 0x10(%rdi),%ebp
lea    0xed5(%rip),%rsi
call   1030 <poly1305_add@plt>
movzbl 0x10(%rbx),%eax
xor    %ecx,%ecx
test   %al,%al
sets   %cl
movdqu (%rbx),%xmm0
movd   %ecx,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
pshufd $0x0,%xmm1,%xmm1
psllw  $0x7,%xmm1
pxor   %xmm2,%xmm2
pcmpgtb %xmm1,%xmm2
movdqa (%rsp),%xmm1
pand   %xmm2,%xmm1
pandn  %xmm0,%xmm2
por    %xmm1,%xmm2
movdqu %xmm2,(%rbx)
cmovns %eax,%ebp
mov    %bpl,0x10(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@poly1305_freeze.minusp = internal constant [17 x i8] c"\05\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FC"
define void @poly1305_freeze(i8* %0) {
%2 = alloca i8*
%3 = alloca [17 x i8]
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
br label %6
6: ; preds = %18, %1
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 17
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = load i32, i32* %5
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %16
store i8 %14, i8* %17
br label %18
18: ; preds = %9
%19 = load i32, i32* %5
%20 = add i32 %19, 1
store i32 %20, i32* %5
br label %6
21: ; preds = %6
%22 = load i8*, i8** %2
%23 = call i32 @poly1305_add(i8* %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @poly1305_freeze.minusp, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 16
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = ashr i32 %27, 7
%29 = sub nsw i32 0, %28
%30 = trunc i32 %29 to i8
store i8 %30, i8* %4
store i32 0, i32* %5
br label %31
31: ; preds = %58, %21
%32 = load i32, i32* %5
%33 = icmp ult i32 %32, 17
br i1 %33, label %34, label %61
34: ; preds = %31
%35 = load i8, i8* %4
%36 = zext i8 %35 to i32
%37 = load i32, i32* %5
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = load i8*, i8** %2
%43 = load i32, i32* %5
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = xor i32 %41, %47
%49 = and i32 %36, %48
%50 = load i8*, i8** %2
%51 = load i32, i32* %5
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = xor i32 %55, %49
%57 = trunc i32 %56 to i8
store i8 %57, i8* %53
br label %58
58: ; preds = %34
%59 = load i32, i32* %5
%60 = add i32 %59, 1
store i32 %60, i32* %5
br label %31
61: ; preds = %31
ret void
}

LLVM IR (-O2):
@poly1305_freeze.minusp = internal constant [17 x i8] c"\05\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\FC"
define void @poly1305_freeze(i8* %0) {
%2 = bitcast i8* %0 to <16 x i8>*
%3 = load <16 x i8>, <16 x i8>* %2
%4 = getelementptr inbounds i8, i8* %0, i64 16
%5 = load i8, i8* %4
%6 = tail call i32 @poly1305_add(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @poly1305_freeze.minusp, i64 0, i64 0))
%7 = load i8, i8* %4
%8 = icmp slt i8 %7, 0
%9 = bitcast i8* %0 to <16 x i8>*
%10 = load <16 x i8>, <16 x i8>* %9
%11 = insertelement <16 x i1> poison, i1 %8, i64 0
%12 = shufflevector <16 x i1> %11, <16 x i1> poison, <16 x i32> zeroinitializer
%13 = select <16 x i1> %12, <16 x i8> %3, <16 x i8> %10
%14 = bitcast i8* %0 to <16 x i8>*
store <16 x i8> %13, <16 x i8>* %14
%15 = select i1 %8, i8 %5, i8 %7
store i8 %15, i8* %4
ret void
}