#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*/ abort();
int /*<<< orphan*/ free(unsigned char *);
unsigned char inner_product(unsigned char *, unsigned char *, size_t);
unsigned char *malloc(size_t);
unsigned char multiply(unsigned char, unsigned char);
unsigned char poly_eval(unsigned char *poly, size_t len, unsigned char at) {
  if (len == 1)
    return *poly;
  unsigned char *x = malloc(len);
  if (!x)
    abort();
  unsigned char at_copy = at;
  x[0] = 1;
  for (int i = 1; i < len; i++) {
    x[i] = at;
    at = multiply(at, at_copy);
  }
  unsigned char ret = inner_product(poly, x, len);
  free(x);
  return ret;
}


x86 assembly (clang, -O0):
<poly_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
cmpq   $0x1,-0x18(%rbp)
jne    117e <poly_eval+0x2e>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1(%rbp)
jmp    1210 <poly_eval+0xc0>
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <poly_eval+0x4d>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x19(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x1,(%rax)
movl   $0x1,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ed <poly_eval+0x9d>
mov    -0x19(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x19(%rbp),%al
movzbl %al,%edi
movzbl -0x29(%rbp),%esi
call   1050 <multiply@plt>
mov    %al,-0x19(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b1 <poly_eval+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <inner_product@plt>
mov    %al,-0x31(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x31(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poly_eval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%rsi
jne    1169 <poly_eval+0x19>
mov    (%r14),%al
jmp    11c5 <poly_eval+0x75>
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rsi,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d4 <poly_eval+0x84>
mov    %rax,%r15
movb   $0x1,(%rax)
cmp    $0x2,%r12
jb     11ab <poly_eval+0x5b>
mov    $0x1,%ebx
movzbl %bpl,%r13d
mov    %bpl,(%r15,%rbx,1)
movzbl %bpl,%edi
mov    %r13d,%esi
call   1050 <multiply@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <poly_eval+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <inner_product@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define zeroext i8 @poly_eval(i8* %0, i64 %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
%11 = alloca i8
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8 %2, i8* %7
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
store i8 %16, i8* %4
br label %53
17: ; preds = %3
%18 = load i64, i64* %6
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %17
%25 = load i8, i8* %7
store i8 %25, i8* %9
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 1, i8* %27
store i32 1, i32* %10
br label %28
28: ; preds = %42, %24
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = load i64, i64* %6
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %28
%34 = load i8, i8* %7
%35 = load i8*, i8** %8
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i8, i8* %7
%40 = load i8, i8* %9
%41 = call zeroext i8 @multiply(i8 zeroext %39, i8 zeroext %40)
store i8 %41, i8* %7
br label %42
42: ; preds = %33
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %28
45: ; preds = %28
%46 = load i8*, i8** %5
%47 = load i8*, i8** %8
%48 = load i64, i64* %6
%49 = call zeroext i8 @inner_product(i8* %46, i8* %47, i64 %48)
store i8 %49, i8* %11
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
%52 = load i8, i8* %11
store i8 %52, i8* %4
br label %53
53: ; preds = %45, %14
%54 = load i8, i8* %4
ret i8 %54
}

LLVM IR (-O2):
define zeroext i8 @poly_eval(i8* %0, i64 %1, i8 zeroext %2) {
%4 = icmp eq i64 %1, 1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i8, i8* %0
br label %24
7: ; preds = %3
%8 = tail call i8* @malloc(i64 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %7
store i8 1, i8* %8
%13 = icmp ugt i64 %1, 1
br i1 %13, label %17, label %14
14: ; preds = %17, %12
%15 = tail call zeroext i8 @inner_product(i8* %0, i8* %8, i64 %1)
%16 = tail call i32 @free(i8* %8)
br label %24
17: ; preds = %12, %17
%18 = phi i64 [ %22, %17 ], [ 1, %12 ]
%19 = phi i8 [ %21, %17 ], [ %2, %12 ]
%20 = getelementptr inbounds i8, i8* %8, i64 %18
store i8 %19, i8* %20
%21 = tail call zeroext i8 @multiply(i8 zeroext %19, i8 zeroext %2)
%22 = add nuw i64 %18, 1
%23 = icmp eq i64 %22, %1
br i1 %23, label %14, label %17
24: ; preds = %14, %5
%25 = phi i8 [ %6, %5 ], [ %15, %14 ]
ret i8 %25
}