#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*/ exit(int);
char *memalign(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int random();
int /*<<< orphan*/ srandom(int);
int /*<<< orphan*/ test_one(char *, char *);
int testcase(void) {
  char *s1;
  char *s2;
  unsigned long i;
  s1 = memalign(128, 256);
  if (!s1) {
    perror("memalign");
    exit(1);
  }
  s2 = memalign(128, 256);
  if (!s2) {
    perror("memalign");
    exit(1);
  }
  srandom(1);
  for (i = 0; i < 10000; i++) {
    unsigned long j;
    unsigned long change;
    for (j = 0; j < 256; j++) {
      s1[j] = random();
    }
    memcpy(s2, s1, 256);
    change = random() % 256;
    s2[change] = random() & 0xff;
    test_one(s1, s2);
  }
  srandom(1);
  for (i = 0; i < 10000; i++) {
    unsigned long j;
    unsigned long change;
    for (j = 0; j < 256; j++) {
      s1[j] = random();
    }
    memcpy(s2, s1, 256);
    for (j = 0; j < 256 / 8; j++) {
      change = random() % 256;
      s2[change] = random() & 0xff;
    }
    test_one(s1, s2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<testcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x80,%edi
mov    $0x100,%esi
call   1050 <memalign@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ac <testcase+0x3c>
lea    0xe63(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x80,%edi
mov    $0x100,%esi
call   1050 <memalign@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <testcase+0x70>
lea    0xe2f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
call   1030 <srandom@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x2710,-0x18(%rbp)
jae    129a <testcase+0x12a>
movq   $0x0,-0x20(%rbp)
cmpq   $0x100,-0x20(%rbp)
jae    123b <testcase+0xcb>
mov    $0x0,%al
call   1060 <random@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1208 <testcase+0x98>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
mov    $0x0,%al
call   1060 <random@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <test_one@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f2 <testcase+0x82>
mov    $0x1,%edi
call   1030 <srandom@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x2710,-0x18(%rbp)
jae    1378 <testcase+0x208>
movq   $0x0,-0x30(%rbp)
cmpq   $0x100,-0x30(%rbp)
jae    12f5 <testcase+0x185>
mov    $0x0,%al
call   1060 <random@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    12c2 <testcase+0x152>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x20,-0x30(%rbp)
jae    135a <testcase+0x1ea>
mov    $0x0,%al
call   1060 <random@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    130f <testcase+0x19f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <test_one@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12ac <testcase+0x13c>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testcase>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x80,%edi
mov    $0x100,%esi
call   1050 <memalign@plt>
test   %rax,%rax
je     12e6 <testcase+0x176>
mov    %rax,%r12
mov    $0x80,%edi
mov    $0x100,%esi
call   1050 <memalign@plt>
test   %rax,%rax
je     12e6 <testcase+0x176>
mov    %rax,%r14
mov    $0x1,%edi
call   1030 <srandom@plt>
xor    %r15d,%r15d
nopl   0x0(%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <random@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    11d0 <testcase+0x60>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
call   1060 <random@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
movslq %eax,%rbx
xor    %eax,%eax
call   1060 <random@plt>
mov    %al,(%r14,%rbx,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <test_one@plt>
add    $0x1,%r15
cmp    $0x2710,%r15
jne    11c0 <testcase+0x50>
mov    $0x1,%edi
call   1030 <srandom@plt>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <random@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1260 <testcase+0xf0>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1040 <memcpy@plt>
mov    $0x20,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1060 <random@plt>
lea    0xff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffff00,%ecx
sub    %ecx,%eax
movslq %eax,%r13
xor    %eax,%eax
call   1060 <random@plt>
mov    %al,(%r14,%r13,1)
add    $0xffffffffffffffff,%rbx
jne    1290 <testcase+0x120>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <test_one@plt>
add    $0x1,%r15
cmp    $0x2710,%r15
jne    1250 <testcase+0xe0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd13(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"memalign\00"
define i32 @testcase() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = call i8* @memalign(i32 128, i32 256)
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i8* @memalign(i32 128, i32 256)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = call i32 @srandom(i32 1)
store i64 0, i64* %3
br label %23
23: ; preds = %55, %21
%24 = load i64, i64* %3
%25 = icmp ult i64 %24, 10000
br i1 %25, label %26, label %58
26: ; preds = %23
store i64 0, i64* %4
br label %27
27: ; preds = %36, %26
%28 = load i64, i64* %4
%29 = icmp ult i64 %28, 256
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = call i32 (...) @random()
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %1
%34 = load i64, i64* %4
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %30
%37 = load i64, i64* %4
%38 = add i64 %37, 1
store i64 %38, i64* %4
br label %27
39: ; preds = %27
%40 = load i8*, i8** %2
%41 = load i8*, i8** %1
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 256)
%43 = call i32 (...) @random()
%44 = srem i32 %43, 256
%45 = sext i32 %44 to i64
store i64 %45, i64* %5
%46 = call i32 (...) @random()
%47 = and i32 %46, 255
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %2
%50 = load i64, i64* %5
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8 %48, i8* %51
%52 = load i8*, i8** %1
%53 = load i8*, i8** %2
%54 = call i32 @test_one(i8* %52, i8* %53)
br label %55
55: ; preds = %39
%56 = load i64, i64* %3
%57 = add i64 %56, 1
store i64 %57, i64* %3
br label %23
58: ; preds = %23
%59 = call i32 @srandom(i32 1)
store i64 0, i64* %3
br label %60
60: ; preds = %100, %58
%61 = load i64, i64* %3
%62 = icmp ult i64 %61, 10000
br i1 %62, label %63, label %103
63: ; preds = %60
store i64 0, i64* %6
br label %64
64: ; preds = %73, %63
%65 = load i64, i64* %6
%66 = icmp ult i64 %65, 256
br i1 %66, label %67, label %76
67: ; preds = %64
%68 = call i32 (...) @random()
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %1
%71 = load i64, i64* %6
%72 = getelementptr inbounds i8, i8* %70, i64 %71
store i8 %69, i8* %72
br label %73
73: ; preds = %67
%74 = load i64, i64* %6
%75 = add i64 %74, 1
store i64 %75, i64* %6
br label %64
76: ; preds = %64
%77 = load i8*, i8** %2
%78 = load i8*, i8** %1
%79 = call i32 @memcpy(i8* %77, i8* %78, i32 256)
store i64 0, i64* %6
br label %80
80: ; preds = %93, %76
%81 = load i64, i64* %6
%82 = icmp ult i64 %81, 32
br i1 %82, label %83, label %96
83: ; preds = %80
%84 = call i32 (...) @random()
%85 = srem i32 %84, 256
%86 = sext i32 %85 to i64
store i64 %86, i64* %7
%87 = call i32 (...) @random()
%88 = and i32 %87, 255
%89 = trunc i32 %88 to i8
%90 = load i8*, i8** %2
%91 = load i64, i64* %7
%92 = getelementptr inbounds i8, i8* %90, i64 %91
store i8 %89, i8* %92
br label %93
93: ; preds = %83
%94 = load i64, i64* %6
%95 = add i64 %94, 1
store i64 %95, i64* %6
br label %80
96: ; preds = %80
%97 = load i8*, i8** %1
%98 = load i8*, i8** %2
%99 = call i32 @test_one(i8* %97, i8* %98)
br label %100
100: ; preds = %96
%101 = load i64, i64* %3
%102 = add i64 %101, 1
store i64 %102, i64* %3
br label %60
103: ; preds = %60
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"memalign\00"
define i32 @testcase() {
%1 = tail call align 128 dereferenceable_or_null(256) i8* @memalign(i32 128, i32 256)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call align 128 dereferenceable_or_null(256) i8* @memalign(i32 128, i32 256)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = tail call i32 @srandom(i32 1)
br label %14
14: ; preds = %12, %23
%15 = phi i64 [ 0, %12 ], [ %32, %23 ]
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = tail call i32 (...) @random()
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 %19, i8* %20
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, 256
br i1 %22, label %23, label %16
23: ; preds = %16
%24 = tail call i32 @memcpy(i8* %7, i8* %1, i32 256)
%25 = tail call i32 (...) @random()
%26 = srem i32 %25, 256
%27 = sext i32 %26 to i64
%28 = tail call i32 (...) @random()
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %7, i64 %27
store i8 %29, i8* %30
%31 = tail call i32 @test_one(i8* %1, i8* %7)
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, 10000
br i1 %33, label %34, label %14
34: ; preds = %23
%35 = tail call i32 @srandom(i32 1)
br label %36
36: ; preds = %34, %57
%37 = phi i64 [ 0, %34 ], [ %59, %57 ]
br label %38
38: ; preds = %36, %38
%39 = phi i64 [ 0, %36 ], [ %43, %38 ]
%40 = tail call i32 (...) @random()
%41 = trunc i32 %40 to i8
%42 = getelementptr inbounds i8, i8* %1, i64 %39
store i8 %41, i8* %42
%43 = add nuw nsw i64 %39, 1
%44 = icmp eq i64 %43, 256
br i1 %44, label %45, label %38
45: ; preds = %38
%46 = tail call i32 @memcpy(i8* %7, i8* %1, i32 256)
br label %47
47: ; preds = %45, %47
%48 = phi i64 [ 0, %45 ], [ %55, %47 ]
%49 = tail call i32 (...) @random()
%50 = srem i32 %49, 256
%51 = sext i32 %50 to i64
%52 = tail call i32 (...) @random()
%53 = trunc i32 %52 to i8
%54 = getelementptr inbounds i8, i8* %7, i64 %51
store i8 %53, i8* %54
%55 = add nuw nsw i64 %48, 1
%56 = icmp eq i64 %55, 32
br i1 %56, label %57, label %47
57: ; preds = %47
%58 = tail call i32 @test_one(i8* %1, i8* %7)
%59 = add nuw nsw i64 %37, 1
%60 = icmp eq i64 %59, 10000
br i1 %60, label %61, label %36
61: ; preds = %57
ret i32 0
}