#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 */
struct gf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
scalar_t__ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ p_rem(struct gf *, unsigned char *, int, int,
                         unsigned char const *, unsigned char const *);
int /*<<< orphan*/ stderr;
void test_rem(struct gf *f, int mlen, const unsigned char *msg,
              unsigned int ppoly, int gplen, const unsigned char *gpoly,
              const unsigned char *sample) {
  int rlen = gplen - 1;
  unsigned char *buf;
  buf = malloc(rlen + 2);
  if (!buf) {
    fprintf(stderr, "tester"
                    ": No core\n");
    exit(1);
  }
  memset(buf, 0xe5, rlen + 2);
  p_rem(f, buf + 1, rlen, mlen, msg, gpoly);
  if (buf[0] != 0xe5 || buf[rlen + 1] != 0xe5) {
    fprintf(stderr,
            "tester"
            ": "
            "p_rem(0x%x,%d,...) destination overflow\n",
            ppoly, rlen);
    exit(1);
  }
  if (memcmp(buf + 1, sample, rlen) != 0) {
    fprintf(stderr,
            "tester"
            ": "
            "p_rem(0x%x,%d,...) sample mismatch\n",
            ppoly, rlen);
    exit(1);
  }
  free(buf);
}


x86 assembly (clang, -O0):
<test_rem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d6 <test_rem+0x66>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
add    $0x2,%edx
mov    $0xe5,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
mov    -0x2c(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1070 <p_rem@plt>
mov    -0x38(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xe5,%eax
jne    1237 <test_rem+0xc7>
mov    -0x38(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xe5,%eax
je     125e <test_rem+0xee>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
mov    0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     12a3 <test_rem+0x133>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x20(%rsp)
mov    %r8d,%ebp
mov    %ecx,0xc(%rsp)
mov    %rdx,0x18(%rsp)
mov    %esi,%r15d
mov    %rdi,%r13
mov    0x60(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x1(%rbp),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1237 <test_rem+0xc7>
mov    %rax,%r14
lea    -0x1(%rbp),%r12d
mov    %rax,%rdi
mov    $0xe5,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r14,%rbx
add    $0x1,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
call   1070 <p_rem@plt>
cmpb   $0xe5,(%r14)
jne    1225 <test_rem+0xb5>
movslq %ebp,%rax
cmpb   $0xe5,(%r14,%rax,1)
jne    1225 <test_rem+0xb5>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r12d,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1258 <test_rem+0xe8>
mov    %r14,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
jmp    1268 <test_rem+0xf8>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
mov    0xc(%rsp),%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.gf = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"tester: No core\0A\00"
@.str.1 = [49 x i8] c"tester: p_rem(0x%x,%d,...) destination overflow\0A\00"
@.str.2 = [44 x i8] c"tester: p_rem(0x%x,%d,...) sample mismatch\0A\00"
define void @test_rem(%struct.gf* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5, i8* %6) {
%8 = alloca %struct.gf*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
store %struct.gf* %0, %struct.gf** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%17 = load i32, i32* %12
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %15
%19 = load i32, i32* %15
%20 = add nsw i32 %19, 2
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %16
%22 = load i8*, i8** %16
%23 = icmp ne i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %7
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %7
%29 = load i8*, i8** %16
%30 = load i32, i32* %15
%31 = add nsw i32 %30, 2
%32 = call i32 @memset(i8* %29, i32 229, i32 %31)
%33 = load %struct.gf*, %struct.gf** %8
%34 = load i8*, i8** %16
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i32, i32* %15
%37 = load i32, i32* %9
%38 = load i8*, i8** %10
%39 = load i8*, i8** %13
%40 = call i32 @p_rem(%struct.gf* %33, i8* %35, i32 %36, i32 %37, i8* %38, i8* %39)
%41 = load i8*, i8** %16
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = icmp ne i32 %44, 229
br i1 %45, label %55, label %46
46: ; preds = %28
%47 = load i8*, i8** %16
%48 = load i32, i32* %15
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = icmp ne i32 %53, 229
br i1 %54, label %55, label %61
55: ; preds = %46, %28
%56 = load i32, i32* @stderr
%57 = load i32, i32* %11
%58 = load i32, i32* %15
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %46
%62 = load i8*, i8** %16
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8*, i8** %14
%65 = load i32, i32* %15
%66 = call i64 @memcmp(i8* %63, i8* %64, i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %61
%69 = load i32, i32* @stderr
%70 = load i32, i32* %11
%71 = load i32, i32* %15
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %70, i32 %71)
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %61
%75 = load i8*, i8** %16
%76 = call i32 @free(i8* %75)
ret void
}

LLVM IR (-O2):
%struct.gf = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"tester: No core\0A\00"
@.str.1 = [49 x i8] c"tester: p_rem(0x%x,%d,...) destination overflow\0A\00"
@.str.2 = [44 x i8] c"tester: p_rem(0x%x,%d,...) sample mismatch\0A\00"
define void @test_rem(%struct.gf* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5, i8* %6) {
%8 = add nsw i32 %4, -1
%9 = add nsw i32 %4, 1
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7
%17 = tail call i32 @memset(i8* %10, i32 229, i32 %9)
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = tail call i32 @p_rem(%struct.gf* %0, i8* %18, i32 %8, i32 %1, i8* %2, i8* %5)
%20 = load i8, i8* %10
%21 = icmp eq i8 %20, -27
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = sext i32 %4 to i64
%24 = getelementptr inbounds i8, i8* %10, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, -27
br i1 %26, label %31, label %27
27: ; preds = %22, %16
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %8)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = tail call i64 @memcmp(i8* %18, i8* %6, i32 %8)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %8)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = tail call i32 @free(i8* %10)
ret void
}