#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__ calloc(int, unsigned long);
unsigned long ceil(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isname(char *, unsigned long);
int log(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
unsigned long strlen(char *);
int strncmp(char *, char *, unsigned long);
int /*<<< orphan*/ strninc(char *, unsigned long);
unsigned long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  char *s;
  unsigned long len, c, lim = 0;
  if (argc != 2) {
    fprintf(stderr, "gen counter\n");
    exit(1);
  }
  len = strlen(argv[1]);
  errno = 0;
  if (!isname(argv[1], len)) {
    lim = strtol(argv[1], NULL, 10);
    len = (lim == 1 ? lim : ceil(log(lim) / log(26)));
    if (errno || lim <= 0) {
      fprintf(stderr, "error: no usable number found in counter, exiting.\n");
      exit(2);
    }
  }
  s = (char *)calloc(sizeof(char), len + 1);
  if (!s) {
    fprintf(stderr, "error: no memory left, exiting.\n");
    exit(3);
  }
  s[len] = '\0';
  for (c = 0; c < len; c++)
    s[c] = 'a';
  while (lim ? lim-- > 1 : strncmp(s, argv[1], len)) {
    puts(s);
    strninc(s, strlen(s));
  }
  puts(s);
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1207 <main+0x47>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2db9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <isname@plt>
cmp    $0x0,%eax
jne    12e5 <main+0x125>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x30(%rbp)
jne    1272 <main+0xb2>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    129d <main+0xdd>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
call   10d0 <log@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x1a,%edi
call   10d0 <log@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <ceil@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d2c(%rip),%rax
cmpq   $0x0,(%rax)
jne    12c1 <main+0x101>
cmpq   $0x0,-0x30(%rbp)
ja     12e0 <main+0x120>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
jmp    12e5 <main+0x125>
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1090 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1325 <main+0x165>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1364 <main+0x1a4>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1339 <main+0x179>
jmp    1369 <main+0x1a9>
cmpq   $0x0,-0x30(%rbp)
je     1397 <main+0x1d7>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x1,%rax
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x40(%rbp)
jmp    13af <main+0x1ef>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncmp@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    $0x0,%eax
je     13e6 <main+0x226>
mov    -0x18(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
call   10c0 <strninc@plt>
jmp    1369 <main+0x1a9>
mov    -0x18(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jne    1313 <main+0x143>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%r15
mov    0x2dde(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <isname@plt>
test   %eax,%eax
je     1216 <main+0x46>
xor    %r12d,%r12d
jmp    126e <main+0x9e>
mov    0x8(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10c0 <strtol@plt>
mov    %rax,%r12
mov    $0x1,%r15d
cmp    $0x1,%rax
je     125a <main+0x8a>
mov    %r12d,%edi
call   10e0 <log@plt>
mov    %eax,%ebx
mov    $0x1a,%edi
call   10e0 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <ceil@plt>
mov    %rax,%r15
cmpq   $0x0,0x0(%rbp)
jne    1351 <main+0x181>
test   %r12,%r12
je     1351 <main+0x181>
lea    0x1(%r15),%rsi
mov    $0x1,%edi
call   10a0 <calloc@plt>
test   %rax,%rax
je     1332 <main+0x162>
mov    %rax,%rbx
movb   $0x0,(%rax,%r15,1)
test   %r15,%r15
je     12c3 <main+0xf3>
mov    %rbx,%rdi
mov    $0x61,%esi
mov    %r15,%rdx
call   1080 <memset@plt>
jmp    12c3 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10d0 <strninc@plt>
test   %r12,%r12
je     12e0 <main+0x110>
xor    %ebp,%ebp
cmp    $0x1,%r12
lea    -0x1(%r12),%r12
setne  %bpl
jmp    12f4 <main+0x124>
nopl   0x0(%rax)
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1040 <strncmp@plt>
mov    %eax,%ebp
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1050 <puts@plt>
test   %ebp,%ebp
jne    12b0 <main+0xe0>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
lea    0xcac(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"gen counter\0A\00"
@errno = global i64 0
@.str.1 = [52 x i8] c"error: no usable number found in counter, exiting.\0A\00"
@.str.2 = [33 x i8] c"error: no memory left, exiting.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %7
store i64 0, i64* @errno
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i64, i64* %7
%25 = call i32 @isname(i8* %23, i64 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %55, label %27
27: ; preds = %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strtol(i8* %30, i32* null, i32 10)
store i64 %31, i64* %9
%32 = load i64, i64* %9
%33 = icmp eq i64 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i64, i64* %9
br label %43
36: ; preds = %27
%37 = load i64, i64* %9
%38 = trunc i64 %37 to i32
%39 = call i32 @log(i32 %38)
%40 = call i32 @log(i32 26)
%41 = sdiv i32 %39, %40
%42 = call i64 @ceil(i32 %41)
br label %43
43: ; preds = %36, %34
%44 = phi i64 [ %35, %34 ], [ %42, %36 ]
store i64 %44, i64* %7
%45 = load i64, i64* @errno
%46 = icmp ne i64 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %43
%48 = load i64, i64* %9
%49 = icmp ule i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %47, %43
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 2)
unreachable
54: ; preds = %47
br label %55
55: ; preds = %54, %16
%56 = load i64, i64* %7
%57 = add i64 %56, 1
%58 = call i64 @calloc(i32 1, i64 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %6
%60 = load i8*, i8** %6
%61 = icmp ne i8* %60, null
br i1 %61, label %66, label %62
62: ; preds = %55
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 3)
unreachable
66: ; preds = %55
%67 = load i8*, i8** %6
%68 = load i64, i64* %7
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
store i64 0, i64* %8
br label %70
70: ; preds = %78, %66
%71 = load i64, i64* %8
%72 = load i64, i64* %7
%73 = icmp ult i64 %71, %72
br i1 %73, label %74, label %81
74: ; preds = %70
%75 = load i8*, i8** %6
%76 = load i64, i64* %8
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8 97, i8* %77
br label %78
78: ; preds = %74
%79 = load i64, i64* %8
%80 = add i64 %79, 1
store i64 %80, i64* %8
br label %70
81: ; preds = %70
br label %82
82: ; preds = %100, %81
%83 = load i64, i64* %9
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %82
%86 = load i64, i64* %9
%87 = add i64 %86, -1
store i64 %87, i64* %9
%88 = icmp ugt i64 %86, 1
%89 = zext i1 %88 to i32
br label %97
90: ; preds = %82
%91 = load i8*, i8** %6
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = load i64, i64* %7
%96 = call i32 @strncmp(i8* %91, i8* %94, i64 %95)
br label %97
97: ; preds = %90, %85
%98 = phi i32 [ %89, %85 ], [ %96, %90 ]
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %107
100: ; preds = %97
%101 = load i8*, i8** %6
%102 = call i32 @puts(i8* %101)
%103 = load i8*, i8** %6
%104 = load i8*, i8** %6
%105 = call i64 @strlen(i8* %104)
%106 = call i32 @strninc(i8* %103, i64 %105)
br label %82
107: ; preds = %97
%108 = load i8*, i8** %6
%109 = call i32 @puts(i8* %108)
%110 = load i8*, i8** %6
%111 = call i32 @free(i8* %110)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"gen counter\0A\00"
@errno = global i64 0
@.str.1 = [52 x i8] c"error: no usable number found in counter, exiting.\0A\00"
@.str.2 = [33 x i8] c"error: no memory left, exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
store i64 0, i64* @errno
%12 = tail call i32 @isname(i8* %10, i64 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %8
%15 = load i8*, i8** %9
%16 = tail call i64 @strtol(i8* nocapture %15, i32* null, i32 10)
%17 = icmp eq i64 %16, 1
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = trunc i64 %16 to i32
%20 = tail call i32 @log(i32 %19)
%21 = tail call i32 @log(i32 26)
%22 = sdiv i32 %20, %21
%23 = tail call i64 @ceil(i32 %22)
br label %24
24: ; preds = %14, %18
%25 = phi i64 [ %23, %18 ], [ 1, %14 ]
%26 = load i64, i64* @errno
%27 = icmp ne i64 %26, 0
%28 = icmp eq i64 %16, 0
%29 = select i1 %27, i1 true, i1 %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%33 = tail call i32 @exit(i32 2)
unreachable
34: ; preds = %24, %8
%35 = phi i64 [ %11, %8 ], [ %25, %24 ]
%36 = phi i64 [ 0, %8 ], [ %16, %24 ]
%37 = add i64 %35, 1
%38 = tail call i64 @calloc(i32 1, i64 %37)
%39 = inttoptr i64 %38 to i8*
%40 = icmp eq i64 %38, 0
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%44 = tail call i32 @exit(i32 3)
unreachable
45: ; preds = %34
%46 = getelementptr inbounds i8, i8* %39, i64 %35
store i8 0, i8* %46
%47 = icmp eq i64 %35, 0
br i1 %47, label %49, label %48
48: ; preds = %45
br label %49
49: ; preds = %48, %45
br label %50
50: ; preds = %49, %65
%51 = phi i64 [ %61, %65 ], [ %36, %49 ]
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %50
%54 = add i64 %51, -1
%55 = icmp ne i64 %51, 1
%56 = zext i1 %55 to i32
br label %60
57: ; preds = %50
%58 = load i8*, i8** %9
%59 = tail call i32 @strncmp(i8* %39, i8* %58, i64 %35)
br label %60
60: ; preds = %57, %53
%61 = phi i64 [ %54, %53 ], [ 0, %57 ]
%62 = phi i32 [ %56, %53 ], [ %59, %57 ]
%63 = icmp eq i32 %62, 0
%64 = tail call i32 @puts(i8* %39)
br i1 %63, label %68, label %65
65: ; preds = %60
%66 = tail call i64 @strlen(i8* %39)
%67 = tail call i32 @strninc(i8* %39, i64 %66)
br label %50
68: ; preds = %60
%69 = tail call i32 @free(i8* %39)
ret i32 0
}