#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 */
scalar_t__ crypto_onetimeauth_poly1305(unsigned char *, unsigned char const *,
                                       size_t, unsigned char const *);
int errno;
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
unsigned char *poly1305_auth(unsigned char *out, const unsigned char *key,
                             const unsigned char *msg, size_t msg_len) {
  int errsv = 0, out_alloc = 0;
  if (!out) {
    if (!(out = malloc(16)))
      return NULL;
    out_alloc = 1;
  }
  if (crypto_onetimeauth_poly1305(out, msg, msg_len, key) < 0) {
    errsv = errno;
    if (out_alloc)
      free(out);
    errno = errsv;
    return NULL;
  }
  return out;
}


x86 assembly (clang, -O0):
<poly1305_auth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <poly1305_auth+0x5d>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1186 <poly1305_auth+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11ec <poly1305_auth+0xbc>
movl   $0x1,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <crypto_onetimeauth_poly1305@plt>
cmp    $0x0,%rax
jge    11e4 <poly1305_auth+0xb4>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11cb <poly1305_auth+0x9b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%ecx
mov    0x2e0b(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ec <poly1305_auth+0xbc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly1305_auth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
test   %rdi,%rdi
je     1167 <poly1305_auth+0x37>
mov    %rdi,%rbx
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <crypto_onetimeauth_poly1305@plt>
test   %rax,%rax
jns    11ab <poly1305_auth+0x7b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%ebp
jmp    11a0 <poly1305_auth+0x70>
mov    $0x10,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11a9 <poly1305_auth+0x79>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <crypto_onetimeauth_poly1305@plt>
test   %rax,%rax
jns    11ab <poly1305_auth+0x7b>
mov    0x2e4a(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2e39(%rip),%rax
mov    %ebp,(%rax)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i8* @poly1305_auth(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %4
%15 = call i8* @malloc(i32 16)
store i8* %15, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8* null, i8** %5
br label %37
18: ; preds = %14
store i32 1, i32* %11
br label %19
19: ; preds = %18, %4
%20 = load i8*, i8** %6
%21 = load i8*, i8** %8
%22 = load i64, i64* %9
%23 = load i8*, i8** %7
%24 = call i64 @crypto_onetimeauth_poly1305(i8* %20, i8* %21, i64 %22, i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %19
%27 = load i32, i32* @errno
store i32 %27, i32* %10
%28 = load i32, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %30, %26
%34 = load i32, i32* %10
store i32 %34, i32* @errno
store i8* null, i8** %5
br label %37
35: ; preds = %19
%36 = load i8*, i8** %6
store i8* %36, i8** %5
br label %37
37: ; preds = %35, %33, %17
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
@errno = global i32 0
define i8* @poly1305_auth(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = tail call i64 @crypto_onetimeauth_poly1305(i8* %7, i8* %2, i64 %3, i8* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %17, label %22
12: ; preds = %4
%13 = tail call i64 @crypto_onetimeauth_poly1305(i8* %0, i8* %2, i64 %3, i8* %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* @errno
br label %20
17: ; preds = %9
%18 = load i32, i32* @errno
%19 = tail call i32 @free(i8* %7)
br label %20
20: ; preds = %15, %17
%21 = phi i32 [ %16, %15 ], [ %18, %17 ]
store i32 %21, i32* @errno
br label %22
22: ; preds = %12, %9, %6, %20
%23 = phi i8* [ null, %20 ], [ null, %6 ], [ %7, %9 ], [ %0, %12 ]
ret i8* %23
}