#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_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *, int,
                           char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int remove_elements(char *starting_string) {
  int n, i;
  char *temp_string = NULL;
  n = strlen(starting_string);
  temp_string = (char *)malloc(n + 1);
  if (!temp_string)
    do {
      fprintf(stderr,
              "A failure occurred in source code file \"%s\" at line %d: "
              "the function %s() returned %d which resolves to \"%s\".\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/jloughry/experiments/refs/heads/"
              "master/optimal_gray_code_banker_sequence/"
              "optimal_gray_code_banker_sequence.c",
              134, "malloc", (int)temp_string, strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  ;
  printf("removing elements, the allowable states from here are:\n");
  strcpy(temp_string, starting_string);
  for (i = n - 1; i >= 0; i--) {
    if (starting_string[i] == '1') {
      temp_string[i] = '0';
      printf("%s\n", temp_string);
    }
    strcpy(temp_string, starting_string);
  }
  free(temp_string);
  return 0;
}


x86 assembly (clang, -O0):
<remove_elements>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <remove_elements+0x98>
jmp    11bf <remove_elements+0x3f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%r9d
lea    0xe12(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    $0x86,%ecx
lea    0xf35(%rip),%r8
mov    %rax,(%rsp)
call   1070 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xf1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1294 <remove_elements+0x114>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1279 <remove_elements+0xf9>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xf03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    123c <remove_elements+0xbc>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_elements>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1214 <remove_elements+0x94>
mov    %rax,%r12
lea    0xf92(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
test   %r15d,%r15d
jle    11fe <remove_elements+0x7e>
mov    %r15d,%ebx
add    $0x1,%rbx
jmp    11e5 <remove_elements+0x65>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11fe <remove_elements+0x7e>
lea    -0x2(%rbx),%eax
cmpb   $0x31,(%r14,%rax,1)
jne    11d0 <remove_elements+0x50>
movb   $0x30,(%r12,%rax,1)
mov    %r12,%rdi
call   1050 <puts@plt>
jmp    11d0 <remove_elements+0x50>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dc5(%rip),%rax
mov    (%rax),%ebx
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,(%rsp)
lea    0xdca(%rip),%rsi
lea    0xe32(%rip),%rdx
lea    0xef2(%rip),%r8
mov    %ebx,%edi
mov    $0x86,%ecx
xor    %r9d,%r9d
call   1070 <fprintf@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [111 x i8] c"A failure occurred in source code file \22%s\22 at line %d: the function %s() returned %d which resolves to \22%s\22.\0A\00"
@.str.1 = [199 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jloughry/experiments/refs/heads/master/optimal_gray_code_banker_sequence/optimal_gray_code_banker_sequence.c\00"
@.str.2 = [7 x i8] c"malloc\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [56 x i8] c"removing elements, the allowable states from here are:\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @remove_elements(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %5
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %25, label %14
14: ; preds = %1
br label %15
15: ; preds = %14
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %17 to i32
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([199 x i8], [199 x i8]* @.str.1, i64 0, i64 0), i32 134, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; No predecessors!
br label %25
25: ; preds = %24, %1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%27 = load i8*, i8** %5
%28 = load i8*, i8** %2
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i32, i32* %3
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %54, %25
%33 = load i32, i32* %4
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %57
35: ; preds = %32
%36 = load i8*, i8** %2
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 49
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i8*, i8** %5
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 48, i8* %47
%48 = load i8*, i8** %5
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %43, %35
%51 = load i8*, i8** %5
%52 = load i8*, i8** %2
%53 = call i32 @strcpy(i8* %51, i8* %52)
br label %54
54: ; preds = %50
%55 = load i32, i32* %4
%56 = add nsw i32 %55, -1
store i32 %56, i32* %4
br label %32
57: ; preds = %32
%58 = load i8*, i8** %5
%59 = call i32 @free(i8* %58)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [111 x i8] c"A failure occurred in source code file \22%s\22 at line %d: the function %s() returned %d which resolves to \22%s\22.\0A\00"
@.str.1 = [199 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jloughry/experiments/refs/heads/master/optimal_gray_code_banker_sequence/optimal_gray_code_banker_sequence.c\00"
@.str.2 = [7 x i8] c"malloc\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [55 x i8] c"removing elements, the allowable states from here are:\00"
define i32 @remove_elements(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([199 x i8], [199 x i8]* @.str.1, i64 0, i64 0), i32 134, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @strcpy(i8* %5, i8* %0)
%17 = icmp sgt i32 %2, 0
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = zext i32 %2 to i64
br label %20
20: ; preds = %18, %30
%21 = phi i64 [ %19, %18 ], [ %22, %30 ]
%22 = add nsw i64 %21, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 49
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = getelementptr inbounds i8, i8* %5, i64 %23
store i8 48, i8* %28
%29 = tail call i32 @puts(i8* %5)
br label %30
30: ; preds = %27, %20
%31 = tail call i32 @strcpy(i8* %5, i8* %0)
%32 = icmp ugt i64 %21, 1
br i1 %32, label %20, label %33
33: ; preds = %30, %14
%34 = tail call i32 @free(i8* %5)
ret i32 0
}