#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ is_correct(char *);
int /*<<< orphan*/ permutation(char *, int);
scalar_t__ set_input(char *, int *);
int main(void) {
  FILE *f_out;
  int err = 0, n = 0;
  char str[10 + 1] = "";
  err += set_input(str, &n);
  err += (f_out = fopen("out.txt", "w")) ? 0 : 2;
  if ((is_correct(str)) && (!err)) {
    int i = 0, len = 0;
    while (str[len] != 0)
      len++;
    while ((i < n) && !permutation(str, len) && !err) {
      err += (fprintf(f_out, "%s\n", str) < 0) ? 3 : 0;
      i++;
    }
  } else
    fprintf(f_out, "bad input");
  fclose(f_out);
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1050 <memset@plt>
lea    -0x23(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <set_input@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
lea    0xe42(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rdx
mov    %rdx,-0x10(%rbp)
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x23(%rbp),%rdi
call   1070 <is_correct@plt>
cmp    $0x0,%rax
je     12be <main+0x14e>
cmpl   $0x0,-0x14(%rbp)
jne    12be <main+0x14e>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
movsbl -0x23(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1230 <main+0xc0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1210 <main+0xa0>
jmp    1235 <main+0xc5>
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    126e <main+0xfe>
lea    -0x23(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1090 <permutation@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
jne    126e <main+0xfe>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    127e <main+0x10e>
jmp    12b9 <main+0x149>
mov    -0x10(%rbp),%rdi
lea    -0x23(%rbp),%rdx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x3,%ecx
cmp    $0x0,%rdx
cmovl  %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1235 <main+0xc5>
jmp    12d0 <main+0x160>
mov    -0x10(%rbp),%rdi
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x4(%rsp)
movl   $0x0,0xf(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <set_input@plt>
mov    %rax,%rbp
lea    0xe4d(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
xor    %eax,%eax
test   %r14,%r14
sete   %al
lea    0x0(%rbp,%rax,2),%r15d
mov    %rbx,%rdi
call   1060 <is_correct@plt>
test   %rax,%rax
je     1255 <main+0xe5>
test   %r15d,%r15d
jne    1255 <main+0xe5>
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    11f0 <main+0x80>
cmpl   $0x0,0x4(%rsp)
jle    1270 <main+0x100>
lea    0x8(%rsp),%r13
lea    0xdfb(%rip),%r12
xor    %ebx,%ebx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
mov    %ebp,%esi
call   1090 <permutation@plt>
or     %r15d,%eax
jne    1273 <main+0x103>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rax,%r15
sar    $0x3f,%r15
and    $0x3,%r15d
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
jl     1220 <main+0xb0>
jmp    1273 <main+0x103>
lea    0xdb2(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
jmp    1273 <main+0x103>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"out.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [10 x i8] c"bad input\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [11 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%8 = bitcast [11 x i8]* %5 to i8*
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%10 = call i64 @set_input(i8* %9, i32* %4)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
%15 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %2
%16 = icmp ne i32* %15, null
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 0, i32 2
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%22 = call i64 @is_correct(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %66
24: ; preds = %0
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %66, label %27
27: ; preds = %24
store i32 0, i32* %6
store i32 0, i32* %7
br label %28
28: ; preds = %35, %27
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %28
38: ; preds = %28
br label %39
39: ; preds = %54, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%45 = load i32, i32* %7
%46 = call i32 @permutation(i8* %44, i32 %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %43
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
br label %52
52: ; preds = %48, %43, %39
%53 = phi i1 [ false, %43 ], [ false, %39 ], [ %51, %48 ]
br i1 %53, label %54, label %65
54: ; preds = %52
%55 = load i32*, i32** %2
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%57 = call i64 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = icmp slt i64 %57, 0
%59 = zext i1 %58 to i64
%60 = select i1 %58, i32 3, i32 0
%61 = load i32, i32* %3
%62 = add nsw i32 %61, %60
store i32 %62, i32* %3
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %39
65: ; preds = %52
br label %69
66: ; preds = %24, %0
%67 = load i32*, i32** %2
%68 = call i64 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %66, %65
%70 = load i32*, i32** %2
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [8 x i8] c"out.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [10 x i8] c"bad input\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%5 = call i64 @set_input(i8* %4, i32* %1)
%6 = trunc i64 %5 to i32
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
%9 = select i1 %8, i32 2, i32 0
%10 = add nsw i32 %9, %6
%11 = call i64 @is_correct(i8* %4)
%12 = icmp eq i64 %11, 0
%13 = icmp ne i32 %10, 0
%14 = select i1 %12, i1 true, i1 %13
br i1 %14, label %38, label %15
15: ; preds = %0, %15
%16 = phi i64 [ %20, %15 ], [ 0, %0 ]
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
%20 = add nuw i64 %16, 1
br i1 %19, label %21, label %15
21: ; preds = %15
%22 = trunc i64 %16 to i32
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %21, %31
%26 = phi i32 [ %35, %31 ], [ 0, %21 ]
%27 = phi i32 [ %34, %31 ], [ 0, %21 ]
%28 = call i32 @permutation(i8* %4, i32 %22)
%29 = or i32 %28, %27
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = call i64 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%33 = icmp slt i64 %32, 0
%34 = select i1 %33, i32 3, i32 0
%35 = add nuw nsw i32 %26, 1
%36 = load i32, i32* %1
%37 = icmp slt i32 %35, %36
br i1 %37, label %25, label %40
38: ; preds = %0
%39 = call i64 @fwrite(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 9, i64 1, i32* %7)
br label %40
40: ; preds = %31, %25, %21, %38
%41 = phi i32 [ %10, %38 ], [ 0, %21 ], [ %34, %31 ], [ %27, %25 ]
%42 = call i32 @fclose(i32* %7)
ret i32 %41
}