#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__ catf(char **, char *, unsigned int, unsigned int, char *);
int /*<<< orphan*/ get_span(unsigned int, unsigned int, unsigned int,
                            unsigned int *, unsigned int *, unsigned int *);
int append_pattern_shifts(char **s, unsigned inputs, unsigned period,
                          unsigned x, char *pattern_bank,
                          unsigned *pattern_pos) {
  unsigned y;
  for (y = 0; y < inputs; ++y) {
    unsigned start, len, is_pipeline;
    get_span(inputs, x, y, &start, &len, &is_pipeline);
    if (is_pipeline || (y - start) / 2 * 2 + 1 >= len) {
      continue;
    }
    unsigned start0 = start + (y - start) / 2 * 2;
    if (y != start0)
      continue;
    if (catf(s,
             "          for(i = 0; i < %1$d; i = i + 1) "
             "%3$s[%2$d + i] <= %3$s[%2$d + (i + 1) %% %1$d];\n",
             period, *pattern_pos, pattern_bank) < 0)
      goto err0;
    *pattern_pos += period;
  }
  return 0;
err0:
  return -1;
}


x86 assembly (clang, -O0):
<append_pattern_shifts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11fb <append_pattern_shifts+0xdb>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1040 <get_span@plt>
cmpl   $0x0,-0x40(%rbp)
jne    118c <append_pattern_shifts+0x6c>
mov    -0x34(%rbp),%eax
sub    -0x38(%rbp),%eax
shr    $0x1,%eax
shl    $0x1,%eax
add    $0x1,%eax
cmp    -0x3c(%rbp),%eax
jb     1191 <append_pattern_shifts+0x71>
jmp    11ed <append_pattern_shifts+0xcd>
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    -0x38(%rbp),%ecx
shr    $0x1,%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     11b6 <append_pattern_shifts+0x96>
jmp    11ed <append_pattern_shifts+0xcd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8
lea    0xe32(%rip),%rsi
call   1030 <catf@plt>
cmp    $0x0,%rax
jge    11e2 <append_pattern_shifts+0xc2>
jmp    1207 <append_pattern_shifts+0xe7>
mov    -0x18(%rbp),%ecx
mov    -0x30(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1144 <append_pattern_shifts+0x24>
movl   $0x0,-0x4(%rbp)
jmp    120e <append_pattern_shifts+0xee>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_pattern_shifts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %rdi,0x18(%rsp)
test   %esi,%esi
je     11dc <append_pattern_shifts+0xbc>
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %r9,0x10(%rsp)
xor    %r14d,%r14d
lea    0xc(%rsp),%r15
lea    0x4(%rsp),%rbp
jmp    1169 <append_pattern_shifts+0x49>
nopl   0x0(%rax)
add    $0x1,%r14d
cmp    %r14d,%ebx
je     11dc <append_pattern_shifts+0xbc>
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %rbp,%r8
lea    0x8(%rsp),%r9
call   1040 <get_span@plt>
cmpl   $0x0,0x8(%rsp)
jne    1160 <append_pattern_shifts+0x40>
mov    0xc(%rsp),%eax
mov    %r14d,%ecx
sub    %eax,%ecx
mov    %ecx,%edx
or     $0x1,%edx
cmp    0x4(%rsp),%edx
jae    1160 <append_pattern_shifts+0x40>
and    $0xfffffffe,%ecx
add    %eax,%ecx
cmp    %ecx,%r14d
jne    1160 <append_pattern_shifts+0x40>
mov    %r15,%rbp
mov    0x10(%rsp),%r15
mov    (%r15),%ecx
mov    0x18(%rsp),%rdi
lea    0xe43(%rip),%rsi
mov    %r13d,%edx
mov    0x20(%rsp),%r8
call   1030 <catf@plt>
test   %rax,%rax
js     11ed <append_pattern_shifts+0xcd>
add    %r13d,(%r15)
mov    %rbp,%r15
lea    0x4(%rsp),%rbp
jmp    1160 <append_pattern_shifts+0x40>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    11de <append_pattern_shifts+0xbe>

LLVM IR (-O0):
@.str = [91 x i8] c" for(i = 0; i < %1$d; i = i + 1) %3$s[%2$d + i] <= %3$s[%2$d + (i + 1) %% %1$d];\0A\00"
define i32 @append_pattern_shifts(i8** %0, i32 %1, i32 %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8** %0, i8*** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32* %5, i32** %13
store i32 0, i32* %14
br label %19
19: ; preds = %66, %6
%20 = load i32, i32* %14
%21 = load i32, i32* %9
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %69
23: ; preds = %19
%24 = load i32, i32* %9
%25 = load i32, i32* %11
%26 = load i32, i32* %14
%27 = call i32 @get_span(i32 %24, i32 %25, i32 %26, i32* %15, i32* %16, i32* %17)
%28 = load i32, i32* %17
%29 = icmp ne i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %23
%31 = load i32, i32* %14
%32 = load i32, i32* %15
%33 = sub i32 %31, %32
%34 = udiv i32 %33, 2
%35 = mul i32 %34, 2
%36 = add i32 %35, 1
%37 = load i32, i32* %16
%38 = icmp uge i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %30, %23
br label %66
40: ; preds = %30
%41 = load i32, i32* %15
%42 = load i32, i32* %14
%43 = load i32, i32* %15
%44 = sub i32 %42, %43
%45 = udiv i32 %44, 2
%46 = mul i32 %45, 2
%47 = add i32 %41, %46
store i32 %47, i32* %18
%48 = load i32, i32* %14
%49 = load i32, i32* %18
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %40
br label %66
52: ; preds = %40
%53 = load i8**, i8*** %8
%54 = load i32, i32* %10
%55 = load i32*, i32** %13
%56 = load i32, i32* %55
%57 = load i8*, i8** %12
%58 = call i64 @catf(i8** %53, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %54, i32 %56, i8* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %52
br label %70
61: ; preds = %52
%62 = load i32, i32* %10
%63 = load i32*, i32** %13
%64 = load i32, i32* %63
%65 = add i32 %64, %62
store i32 %65, i32* %63
br label %66
66: ; preds = %61, %51, %39
%67 = load i32, i32* %14
%68 = add i32 %67, 1
store i32 %68, i32* %14
br label %19
69: ; preds = %19
store i32 0, i32* %7
br label %71
70: ; preds = %60
store i32 -1, i32* %7
br label %71
71: ; preds = %70, %69
%72 = load i32, i32* %7
ret i32 %72
}

LLVM IR (-O2):
@.str = [91 x i8] c" for(i = 0; i < %1$d; i = i + 1) %3$s[%2$d + i] <= %3$s[%2$d + (i + 1) %% %1$d];\0A\00"
define i32 @append_pattern_shifts(i8** %0, i32 %1, i32 %2, i32 %3, i8* %4, i32* nocapture %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = icmp eq i32 %1, 0
br i1 %10, label %41, label %11
11: ; preds = %6
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = bitcast i32* %9 to i8*
br label %15
15: ; preds = %11, %38
%16 = phi i32 [ 0, %11 ], [ %39, %38 ]
%17 = call i32 @get_span(i32 %1, i32 %3, i32 %16, i32* %7, i32* %8, i32* %9)
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = load i32, i32* %7
%22 = sub i32 %16, %21
%23 = or i32 %22, 1
%24 = load i32, i32* %8
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %20
%27 = and i32 %22, -2
%28 = add i32 %27, %21
%29 = icmp eq i32 %16, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* %5
%32 = call i64 @catf(i8** %0, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %31, i8* %4)
%33 = icmp slt i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i32, i32* %5
%36 = add i32 %35, %2
store i32 %36, i32* %5
br label %38
37: ; preds = %30
br label %41
38: ; preds = %20, %15, %34, %26
%39 = add nuw i32 %16, 1
%40 = icmp eq i32 %39, %1
br i1 %40, label %41, label %15
41: ; preds = %38, %6, %37
%42 = phi i32 [ -1, %37 ], [ 0, %6 ], [ 0, %38 ]
ret i32 %42
}