#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*/ getNextLabel();
int getchar();
int /*<<< orphan*/ initLabelGenerator();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ setLabelNumber(int);
int /*<<< orphan*/ setLabelPrefix(char *);
int main(int argc, const char *argv[]) {
  char prefix[100];
  int c, index;
  int i = 0;
  initLabelGenerator();
  printf("This program tests the labelseq abstraction.\n");
  printf("Prefix to use for labels: ");
  while ((c = getchar()) != '\n') {
    prefix[i++] = c;
  }
  prefix[i] = '\0';
  printf("Starting number: ");
  scanf("%d", &index);
  setLabelPrefix(prefix);
  setLabelNumber(index);
  for (int j = 0; j < 5; j++) {
    getNextLabel();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    $0x0,%al
call   1060 <initLabelGenerator@plt>
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x84(%rbp)
cmp    $0xa,%eax
je     11ec <main+0x7c>
mov    -0x84(%rbp),%eax
mov    %al,%cl
mov    -0x8c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8c(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
jmp    11b2 <main+0x42>
movslq -0x8c(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
lea    -0x88(%rbp),%rsi
call   1090 <scanf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <setLabelPrefix@plt>
mov    -0x88(%rbp),%edi
call   1070 <setLabelNumber@plt>
movl   $0x0,-0x90(%rbp)
cmpl   $0x5,-0x90(%rbp)
jge    125d <main+0xed>
mov    $0x0,%al
call   1040 <getNextLabel@plt>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    1235 <main+0xc5>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <initLabelGenerator@plt>
lea    0xe98(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5c(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%eax
je     11d6 <main+0x56>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0xa,%eax
jne    11c0 <main+0x40>
mov    %ebx,%ebx
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
lea    0xe3f(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
lea    0x10(%rsp),%rdi
call   1030 <setLabelPrefix@plt>
mov    0xc(%rsp),%edi
call   1080 <setLabelNumber@plt>
xor    %eax,%eax
call   1040 <getNextLabel@plt>
xor    %eax,%eax
call   1040 <getNextLabel@plt>
xor    %eax,%eax
call   1040 <getNextLabel@plt>
xor    %eax,%eax
call   1040 <getNextLabel@plt>
xor    %eax,%eax
call   1040 <getNextLabel@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"This program tests the labelseq abstraction.\0A\00"
@.str.1 = [27 x i8] c"Prefix to use for labels: \00"
@.str.2 = [18 x i8] c"Starting number: \00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = call i32 (...) @initLabelGenerator()
%12 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %17, %2
%15 = call i32 (...) @getchar()
store i32 %15, i32* %7
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %7
%19 = trunc i32 %18 to i8
%20 = load i32, i32* %9
%21 = add nsw i32 %20, 1
store i32 %21, i32* %9
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %22
store i8 %19, i8* %23
br label %14
24: ; preds = %14
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%31 = call i32 @setLabelPrefix(i8* %30)
%32 = load i32, i32* %8
%33 = call i32 @setLabelNumber(i32 %32)
store i32 0, i32* %10
br label %34
34: ; preds = %39, %24
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 5
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = call i32 (...) @getNextLabel()
br label %39
39: ; preds = %37
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %34
42: ; preds = %34
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"Prefix to use for labels: \00"
@.str.2 = [18 x i8] c"Starting number: \00"
@.str.3 = [3 x i8] c"%d\00"
@str = [45 x i8] c"This program tests the labelseq abstraction.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (...) @initLabelGenerator()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 (...) @getchar()
%11 = icmp eq i32 %10, 10
br i1 %11, label %22, label %12
12: ; preds = %2, %12
%13 = phi i64 [ %16, %12 ], [ 0, %2 ]
%14 = phi i32 [ %18, %12 ], [ %10, %2 ]
%15 = trunc i32 %14 to i8
%16 = add nuw i64 %13, 1
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %13
store i8 %15, i8* %17
%18 = tail call i32 (...) @getchar()
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = and i64 %16, 4294967295
br label %22
22: ; preds = %20, %2
%23 = phi i64 [ 0, %2 ], [ %21, %20 ]
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %23
store i8 0, i8* %24
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%27 = call i32 @setLabelPrefix(i8* %5)
%28 = load i32, i32* %4
%29 = call i32 @setLabelNumber(i32 %28)
%30 = call i32 (...) @getNextLabel()
%31 = call i32 (...) @getNextLabel()
%32 = call i32 (...) @getNextLabel()
%33 = call i32 (...) @getNextLabel()
%34 = call i32 (...) @getNextLabel()
ret i32 0
}