#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 millipede {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *);
int getopt(int, char **, char *);
char *millipede_body(struct millipede *);
char *millipede_head(struct millipede *);
struct millipede *millipede_init();
scalar_t__ millipede_set_body(struct millipede *, char *);
scalar_t__ millipede_set_curve(struct millipede *, unsigned int);
int /*<<< orphan*/ millipede_set_dir(struct millipede *, int);
scalar_t__ millipede_set_head(struct millipede *, char *);
scalar_t__ millipede_set_start(struct millipede *, unsigned int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, char *);
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
unsigned int strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  struct millipede *millipede;
  int opt;
  unsigned int size = 10;
  int dir = -1;
  unsigned int start = 2;
  unsigned int curve = 4;
  int i;
  while ((opt = getopt(argc, argv, "s:d:p:c:")) != -1) {
    switch (opt) {
    case 's':
      size = strtoul(optarg, NULL, 10);
      break;
    case 'd':
      dir = strtol(optarg, NULL, 10);
      break;
    case 'p':
      start = strtoul(optarg, NULL, 10);
      break;
    case 'c':
      curve = strtoul(optarg, NULL, 10);
      break;
    }
  }
  if ((millipede = millipede_init()) == NULL)
    errx(1, "millipede_init: error");
  if (millipede_set_head(millipede, "\\o o/"))
    errx(1, "millipede_set_head: error");
  if (millipede_set_body(millipede, "|=(###)=|"))
    errx(1, "millipede_set_head: error");
  if (millipede_set_start(millipede, start))
    errx(1, "millipede_set_start: error\n");
  if (millipede_set_curve(millipede, curve))
    errx(1, "millipede_set_curve: error\n");
  millipede_set_dir(millipede, dir);
  printf("%s\n", millipede_head(millipede));
  for (i = 0; i < size; i++)
    printf("%s\n", millipede_body(millipede));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x2,-0x28(%rbp)
movl   $0x4,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe34(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     12c6 <main+0xf6>
mov    -0x1c(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x10,%eax
ja     12c1 <main+0xf1>
mov    -0x38(%rbp),%rax
lea    0xdbf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
jmp    12c1 <main+0xf1>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,-0x24(%rbp)
jmp    12c1 <main+0xf1>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,-0x28(%rbp)
jmp    12c1 <main+0xf1>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
jmp    1202 <main+0x32>
mov    $0x0,%al
call   1050 <millipede_init@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12ec <main+0x11c>
mov    $0x1,%edi
lea    0xd66(%rip),%rsi
call   1070 <errx@plt>
mov    -0x18(%rbp),%rdi
lea    0xd6c(%rip),%rsi
call   1060 <millipede_set_head@plt>
cmp    $0x0,%rax
je     1317 <main+0x147>
mov    $0x1,%edi
lea    0xd57(%rip),%rsi
call   1070 <errx@plt>
mov    -0x18(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   1030 <millipede_set_body@plt>
cmp    $0x0,%rax
je     1342 <main+0x172>
mov    $0x1,%edi
lea    0xd2c(%rip),%rsi
call   1070 <errx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   10d0 <millipede_set_start@plt>
cmp    $0x0,%rax
je     1369 <main+0x199>
mov    $0x1,%edi
lea    0xd29(%rip),%rsi
call   1070 <errx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <millipede_set_curve@plt>
cmp    $0x0,%rax
je     1390 <main+0x1c0>
mov    $0x1,%edi
lea    0xd1e(%rip),%rsi
call   1070 <errx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10f0 <millipede_set_dir@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <millipede_head@plt>
mov    %rax,%rsi
lea    0xd16(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    13ed <main+0x21d>
mov    -0x18(%rbp),%rdi
call   10a0 <millipede_body@plt>
mov    %rax,%rsi
lea    0xceb(%rip),%rdi
call   1080 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13bb <main+0x1eb>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x4,0x10(%rsp)
movl   $0x2,0xc(%rsp)
movl   $0xffffffff,0x14(%rsp)
ff
mov    $0xa,%r13d
lea    0xe3c(%rip),%r14
lea    0xdf1(%rip),%r15
mov    0x2de2(%rip),%r12
jmp    1225 <main+0x55>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     129a <main+0xca>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10c0 <getopt@plt>
lea    -0x63(%rax),%ecx
cmp    $0x10,%ecx
ja     1220 <main+0x50>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,0x10(%rsp)
jmp    1225 <main+0x55>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
mov    %eax,0x14(%rsp)
jmp    1225 <main+0x55>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,0xc(%rsp)
jmp    1225 <main+0x55>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10e0 <strtoul@plt>
mov    %eax,%r13d
jmp    1225 <main+0x55>
xor    %eax,%eax
call   1050 <millipede_init@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12ba <main+0xea>
lea    0xd9d(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
lea    0xda2(%rip),%rsi
mov    %rbp,%rdi
call   1060 <millipede_set_head@plt>
test   %rax,%rax
je     12df <main+0x10f>
lea    0xd94(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
lea    0xd9d(%rip),%rsi
mov    %rbp,%rdi
call   1030 <millipede_set_body@plt>
test   %rax,%rax
je     1304 <main+0x134>
lea    0xd6f(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
mov    %rbp,%rdi
mov    0xc(%rsp),%esi
call   10d0 <millipede_set_start@plt>
test   %rax,%rax
je     1326 <main+0x156>
lea    0xd71(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%esi
call   1040 <millipede_set_curve@plt>
test   %rax,%rax
je     1348 <main+0x178>
lea    0xd6b(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
mov    %rbp,%rdi
mov    0x14(%rsp),%esi
call   10f0 <millipede_set_dir@plt>
mov    %rbp,%rdi
call   10b0 <millipede_head@plt>
lea    0xd62(%rip),%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
test   %r13d,%r13d
je     1399 <main+0x1c9>
lea    0xd4e(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10a0 <millipede_body@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <printf@plt>
add    $0xffffffff,%r13d
jne    1380 <main+0x1b0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.millipede = type { i32 }
@.str = [9 x i8] c"s:d:p:c:\00"
@optarg = global i32 0
@.str.1 = [22 x i8] c"millipede_init: error\00"
@.str.2 = [6 x i8] c"\\o o/\00"
@.str.3 = [26 x i8] c"millipede_set_head: error\00"
@.str.4 = [10 x i8] c"|=(###)=|\00"
@.str.5 = [28 x i8] c"millipede_set_start: error\0A\00"
@.str.6 = [28 x i8] c"millipede_set_curve: error\0A\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.millipede*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %8
store i32 -1, i32* %9
store i32 2, i32* %10
store i32 4, i32* %11
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %7
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %33
18: ; preds = %13
%19 = load i32, i32* %7
switch i32 %19, label %32 [
i32 115, label %20
i32 100, label %23
i32 112, label %26
i32 99, label %29
]
20: ; preds = %18
%21 = load i32, i32* @optarg
%22 = call i32 @strtoul(i32 %21, i32* null, i32 10)
store i32 %22, i32* %8
br label %32
23: ; preds = %18
%24 = load i32, i32* @optarg
%25 = call i32 @strtol(i32 %24, i32* null, i32 10)
store i32 %25, i32* %9
br label %32
26: ; preds = %18
%27 = load i32, i32* @optarg
%28 = call i32 @strtoul(i32 %27, i32* null, i32 10)
store i32 %28, i32* %10
br label %32
29: ; preds = %18
%30 = load i32, i32* @optarg
%31 = call i32 @strtoul(i32 %30, i32* null, i32 10)
store i32 %31, i32* %11
br label %32
32: ; preds = %18, %29, %26, %23, %20
br label %13
33: ; preds = %13
%34 = call %struct.millipede* (...) @millipede_init()
store %struct.millipede* %34, %struct.millipede** %6
%35 = icmp eq %struct.millipede* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load %struct.millipede*, %struct.millipede** %6
%40 = call i64 @millipede_set_head(%struct.millipede* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load %struct.millipede*, %struct.millipede** %6
%46 = call i64 @millipede_set_body(%struct.millipede* %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = load %struct.millipede*, %struct.millipede** %6
%52 = load i32, i32* %10
%53 = call i64 @millipede_set_start(%struct.millipede* %51, i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %50
%58 = load %struct.millipede*, %struct.millipede** %6
%59 = load i32, i32* %11
%60 = call i64 @millipede_set_curve(%struct.millipede* %58, i32 %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
%65 = load %struct.millipede*, %struct.millipede** %6
%66 = load i32, i32* %9
%67 = call i32 @millipede_set_dir(%struct.millipede* %65, i32 %66)
%68 = load %struct.millipede*, %struct.millipede** %6
%69 = call i8* @millipede_head(%struct.millipede* %68)
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %69)
store i32 0, i32* %12
br label %71
71: ; preds = %79, %64
%72 = load i32, i32* %12
%73 = load i32, i32* %8
%74 = icmp ult i32 %72, %73
br i1 %74, label %75, label %82
75: ; preds = %71
%76 = load %struct.millipede*, %struct.millipede** %6
%77 = call i8* @millipede_body(%struct.millipede* %76)
%78 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %77)
br label %79
79: ; preds = %75
%80 = load i32, i32* %12
%81 = add nsw i32 %80, 1
store i32 %81, i32* %12
br label %71
82: ; preds = %71
ret i32 0
}

LLVM IR (-O2):
%struct.millipede = type { i32 }
@.str = [9 x i8] c"s:d:p:c:\00"
@optarg = global i32 0
@.str.1 = [22 x i8] c"millipede_init: error\00"
@.str.2 = [6 x i8] c"\\o o/\00"
@.str.3 = [26 x i8] c"millipede_set_head: error\00"
@.str.4 = [10 x i8] c"|=(###)=|\00"
@.str.5 = [28 x i8] c"millipede_set_start: error\0A\00"
@.str.6 = [28 x i8] c"millipede_set_curve: error\0A\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %19, %2
%4 = phi i32 [ %21, %19 ], [ 10, %2 ]
%5 = phi i32 [ %9, %19 ], [ -1, %2 ]
%6 = phi i32 [ %13, %19 ], [ 2, %2 ]
%7 = phi i32 [ %16, %19 ], [ 4, %2 ]
br label %8
8: ; preds = %3, %22
%9 = phi i32 [ %5, %3 ], [ %24, %22 ]
%10 = phi i32 [ %6, %3 ], [ %13, %22 ]
%11 = phi i32 [ %7, %3 ], [ %16, %22 ]
br label %12
12: ; preds = %8, %25
%13 = phi i32 [ %10, %8 ], [ %27, %25 ]
%14 = phi i32 [ %11, %8 ], [ %16, %25 ]
br label %15
15: ; preds = %12, %28
%16 = phi i32 [ %14, %12 ], [ %30, %28 ]
br label %17
17: ; preds = %15, %17
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
switch i32 %18, label %17 [
i32 -1, label %31
i32 115, label %19
i32 100, label %22
i32 112, label %25
i32 99, label %28
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = tail call i32 @strtoul(i32 %20, i32* null, i32 10)
br label %3
22: ; preds = %17
%23 = load i32, i32* @optarg
%24 = tail call i32 @strtol(i32 %23, i32* null, i32 10)
br label %8
25: ; preds = %17
%26 = load i32, i32* @optarg
%27 = tail call i32 @strtoul(i32 %26, i32* null, i32 10)
br label %12
28: ; preds = %17
%29 = load i32, i32* @optarg
%30 = tail call i32 @strtoul(i32 %29, i32* null, i32 10)
br label %15
31: ; preds = %17
%32 = tail call %struct.millipede* (...) @millipede_init()
%33 = icmp eq %struct.millipede* %32, null
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = tail call i64 @millipede_set_head(%struct.millipede* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = tail call i64 @millipede_set_body(%struct.millipede* %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = tail call i64 @millipede_set_start(%struct.millipede* %32, i32 %13)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = tail call i64 @millipede_set_curve(%struct.millipede* %32, i32 %16)
%53 = icmp eq i64 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %51
%55 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = tail call i32 @millipede_set_dir(%struct.millipede* %32, i32 %9)
%58 = tail call i8* @millipede_head(%struct.millipede* %32)
%59 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %58)
%60 = icmp eq i32 %4, 0
br i1 %60, label %67, label %61
61: ; preds = %56, %61
%62 = phi i32 [ %65, %61 ], [ 0, %56 ]
%63 = tail call i8* @millipede_body(%struct.millipede* %32)
%64 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %63)
%65 = add nuw i32 %62, 1
%66 = icmp eq i32 %65, %4
br i1 %66, label %67, label %61
67: ; preds = %61, %56
ret i32 0
}