#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 EOF;
int atoi(char *);
int /*<<< orphan*/ err_msg(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int tenpow(int);
int enter_number() {
  char mstr[5] = {'\0', '\0', '\0', '\0', '\0'};
  int c;
  int input;
  int in_digits[4] = {0, 0, 0, 0};
  bool reinput;
  do {
    reinput = false;
    printf("Input a 4-digit number:");
    if (fgets(mstr, sizeof mstr, stdin) == NULL)
      err_msg("Something's got wrong, I'd better quit...\n");
    bool flag = false;
    if (mstr[0] != '\n' && mstr[1] != '\n' && mstr[2] != '\n' &&
        mstr[3] != '\n')
      while ((c = getchar()) != '\n' && c != EOF)
        flag = true;
    if (flag == true) {
      fprintf(stderr, "Input too long!\n");
      reinput = true;
      continue;
    }
    input = atoi(mstr);
    if (input < 1000 || input > 9999) {
      fprintf(stderr, "Must be a number between 1000 and 9999!\n");
      reinput = true;
      continue;
    }
    for (int i = 0; i < 4; i++)
      in_digits[i] = (int)(input / tenpow(3 - i)) % 10;
    if (in_digits[0] == in_digits[1] || in_digits[1] == in_digits[2] ||
        in_digits[2] == in_digits[3] || in_digits[0] == in_digits[2] ||
        in_digits[0] == in_digits[3] || in_digits[1] == in_digits[3]) {
      fprintf(stderr, "Four digits must be unique.\n");
      reinput = true;
      continue;
    }
  } while (reinput);
  return input;
}


x86 assembly (clang, -O0):
<enter_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x5(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x0,-0x24(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
lea    -0x5(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11e8 <enter_number+0x68>
lea    0xe35(%rip),%rdi
call   1090 <err_msg@plt>
movl   $0x0,-0x28(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     1275 <enter_number+0xf5>
movsbl -0x4(%rbp),%eax
cmp    $0xa,%eax
je     1275 <enter_number+0xf5>
movsbl -0x3(%rbp),%eax
cmp    $0xa,%eax
je     1275 <enter_number+0xf5>
movsbl -0x2(%rbp),%eax
cmp    $0xa,%eax
je     1275 <enter_number+0xf5>
jmp    1228 <enter_number+0xa8>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x2d(%rbp)
je     1254 <enter_number+0xd4>
mov    -0xc(%rbp),%eax
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1264 <enter_number+0xe4>
jmp    1270 <enter_number+0xf0>
movl   $0x1,-0x28(%rbp)
jmp    1228 <enter_number+0xa8>
jmp    1275 <enter_number+0xf5>
cmpl   $0x1,-0x28(%rbp)
jne    12a0 <enter_number+0x120>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    139f <enter_number+0x21f>
lea    -0x5(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x3e8,-0x10(%rbp)
jl     12c6 <enter_number+0x146>
cmpl   $0x270f,-0x10(%rbp)
jle    12e7 <enter_number+0x167>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    139f <enter_number+0x21f>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    1331 <enter_number+0x1b1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x3,%edi
sub    -0x2c(%rbp),%edi
call   1040 <tenpow@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq -0x2c(%rbp),%rax
mov    %edx,-0x20(%rbp,%rax,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ee <enter_number+0x16e>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1379 <enter_number+0x1f9>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1379 <enter_number+0x1f9>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1379 <enter_number+0x1f9>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1379 <enter_number+0x1f9>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1379 <enter_number+0x1f9>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    139a <enter_number+0x21a>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    0xcf4(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    139f <enter_number+0x21f>
jmp    139f <enter_number+0x21f>
cmpl   $0x0,-0x24(%rbp)
jne    11a8 <enter_number+0x28>
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enter_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    %rsp,%r12
mov    0x2e4f(%rip),%r14
jmp    11ae <enter_number+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <fprintf@plt>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0x5,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    11e1 <enter_number+0x71>
lea    0xe4c(%rip),%rdi
call   1080 <err_msg@plt>
movd   (%rsp),%xmm0
pcmpeqb 0xe12(%rip),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
movmskps %xmm0,%eax
test   %eax,%eax
jne    1240 <enter_number+0xd0>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
setne  %cl
cmp    (%r14),%eax
setne  %bl
and    %cl,%bl
cmp    $0x1,%bl
jne    1240 <enter_number+0xd0>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
je     1231 <enter_number+0xc1>
cmp    (%r14),%eax
jne    1220 <enter_number+0xb0>
lea    0xe1b(%rip),%rsi
test   %bl,%bl
jne    11a0 <enter_number+0x30>
mov    %r12,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    -0x2710(%rbx),%eax
lea    0xe0d(%rip),%rsi
cmp    $0xffffdcd8,%eax
jb     11a0 <enter_number+0x30>
mov    $0x3,%edi
call   1040 <tenpow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%r13d
movswl %r13w,%eax
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
mov    $0x2,%edi
call   1040 <tenpow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
movswl %bp,%eax
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
mov    $0x1,%edi
call   1040 <tenpow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%r15d
movswl %r15w,%eax
imul   $0x6667,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
xor    %edi,%edi
call   1040 <tenpow@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
movswl %ax,%ecx
imul   $0x6667,%ecx,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    0xd74(%rip),%rsi
cmp    %bp,%r13w
je     11a0 <enter_number+0x30>
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
lea    0xd5e(%rip),%rsi
cmp    %r15w,%bp
je     11a0 <enter_number+0x30>
lea    0xd4d(%rip),%rsi
cmp    %ax,%r15w
je     11a0 <enter_number+0x30>
lea    0xd3c(%rip),%rsi
cmp    %r15w,%r13w
je     11a0 <enter_number+0x30>
lea    0xd2b(%rip),%rsi
cmp    %ax,%r13w
je     11a0 <enter_number+0x30>
lea    0xd1a(%rip),%rsi
cmp    %ax,%bp
je     11a0 <enter_number+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Input a 4-digit number:\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"Something's got wrong, I'd better quit...\0A\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"Input too long!\0A\00"
@.str.3 = [41 x i8] c"Must be a number between 1000 and 9999!\0A\00"
@.str.4 = [29 x i8] c"Four digits must be unique.\0A\00"
define i32 @enter_number() {
%1 = alloca [5 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [5 x i8]* %1 to i8*
%9 = bitcast [4 x i32]* %4 to i8*
br label %10
10: ; preds = %124, %0
store i32 0, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %12, i32 5, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @err_msg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
store i32 0, i32* %6
%19 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %50
23: ; preds = %18
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %50
28: ; preds = %23
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %50
33: ; preds = %28
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 3
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 10
br i1 %37, label %38, label %50
38: ; preds = %33
br label %39
39: ; preds = %48, %38
%40 = call i32 (...) @getchar()
store i32 %40, i32* %2
%41 = icmp ne i32 %40, 10
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* %2
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br label %46
46: ; preds = %42, %39
%47 = phi i1 [ false, %39 ], [ %45, %42 ]
br i1 %47, label %48, label %49
48: ; preds = %46
store i32 1, i32* %6
br label %39
49: ; preds = %46
br label %50
50: ; preds = %49, %33, %28, %23, %18
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %124
56: ; preds = %50
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %3
%59 = load i32, i32* %3
%60 = icmp slt i32 %59, 1000
br i1 %60, label %64, label %61
61: ; preds = %56
%62 = load i32, i32* %3
%63 = icmp sgt i32 %62, 9999
br i1 %63, label %64, label %67
64: ; preds = %61, %56
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %124
67: ; preds = %61
store i32 0, i32* %7
br label %68
68: ; preds = %81, %67
%69 = load i32, i32* %7
%70 = icmp slt i32 %69, 4
br i1 %70, label %71, label %84
71: ; preds = %68
%72 = load i32, i32* %3
%73 = load i32, i32* %7
%74 = sub nsw i32 3, %73
%75 = call i32 @tenpow(i32 %74)
%76 = sdiv i32 %72, %75
%77 = srem i32 %76, 10
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %79
store i32 %77, i32* %80
br label %81
81: ; preds = %71
%82 = load i32, i32* %7
%83 = add nsw i32 %82, 1
store i32 %83, i32* %7
br label %68
84: ; preds = %68
%85 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%86 = load i32, i32* %85
%87 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%88 = load i32, i32* %87
%89 = icmp eq i32 %86, %88
br i1 %89, label %120, label %90
90: ; preds = %84
%91 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%92 = load i32, i32* %91
%93 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%94 = load i32, i32* %93
%95 = icmp eq i32 %92, %94
br i1 %95, label %120, label %96
96: ; preds = %90
%97 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%98 = load i32, i32* %97
%99 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%100 = load i32, i32* %99
%101 = icmp eq i32 %98, %100
br i1 %101, label %120, label %102
102: ; preds = %96
%103 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%104 = load i32, i32* %103
%105 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%106 = load i32, i32* %105
%107 = icmp eq i32 %104, %106
br i1 %107, label %120, label %108
108: ; preds = %102
%109 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%110 = load i32, i32* %109
%111 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%112 = load i32, i32* %111
%113 = icmp eq i32 %110, %112
br i1 %113, label %120, label %114
114: ; preds = %108
%115 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%116 = load i32, i32* %115
%117 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%118 = load i32, i32* %117
%119 = icmp eq i32 %116, %118
br i1 %119, label %120, label %123
120: ; preds = %114, %108, %102, %96, %90, %84
%121 = load i32, i32* @stderr
%122 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %5
br label %124
123: ; preds = %114
br label %124
124: ; preds = %123, %120, %64, %53
%125 = load i32, i32* %5
%126 = icmp ne i32 %125, 0
br i1 %126, label %10, label %127
127: ; preds = %124
%128 = load i32, i32* %3
ret i32 %128
}

LLVM IR (-O2):
@.str = [24 x i8] c"Input a 4-digit number:\00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"Something's got wrong, I'd better quit...\0A\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"Input too long!\0A\00"
@.str.3 = [41 x i8] c"Must be a number between 1000 and 9999!\0A\00"
@.str.4 = [29 x i8] c"Four digits must be unique.\0A\00"
define i32 @enter_number() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = bitcast [5 x i8]* %1 to <4 x i8>*
br label %4
4: ; preds = %62, %0
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %2, i32 5, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @err_msg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = load <4 x i8>, <4 x i8>* %3
%13 = freeze <4 x i8> %12
%14 = icmp eq <4 x i8> %13, <i8 10, i8 10, i8 10, i8 10>
%15 = bitcast <4 x i1> %14 to i4
%16 = icmp eq i4 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %11
%18 = call i32 (...) @getchar()
%19 = icmp ne i32 %18, 10
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %18, %20
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %30
23: ; preds = %17, %23
%24 = call i32 (...) @getchar()
%25 = icmp ne i32 %24, 10
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %24, %26
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %23, label %29
29: ; preds = %23
br i1 %22, label %62, label %30
30: ; preds = %17, %11, %29
%31 = call i32 @atoi(i8* %2)
%32 = add i32 %31, -10000
%33 = icmp ult i32 %32, -9000
br i1 %33, label %62, label %34
34: ; preds = %30
%35 = call i32 @tenpow(i32 3)
%36 = sdiv i32 %31, %35
%37 = trunc i32 %36 to i16
%38 = srem i16 %37, 10
%39 = call i32 @tenpow(i32 2)
%40 = sdiv i32 %31, %39
%41 = trunc i32 %40 to i16
%42 = srem i16 %41, 10
%43 = call i32 @tenpow(i32 1)
%44 = sdiv i32 %31, %43
%45 = trunc i32 %44 to i16
%46 = srem i16 %45, 10
%47 = call i32 @tenpow(i32 0)
%48 = sdiv i32 %31, %47
%49 = trunc i32 %48 to i16
%50 = srem i16 %49, 10
%51 = icmp eq i16 %38, %42
%52 = icmp eq i16 %42, %46
%53 = select i1 %51, i1 true, i1 %52
br i1 %53, label %62, label %54
54: ; preds = %34
%55 = icmp eq i16 %46, %50
%56 = icmp eq i16 %38, %46
%57 = select i1 %55, i1 true, i1 %56
%58 = icmp eq i16 %38, %50
%59 = select i1 %57, i1 true, i1 %58
%60 = icmp eq i16 %42, %50
%61 = select i1 %59, i1 true, i1 %60
br i1 %61, label %62, label %66
62: ; preds = %34, %54, %30, %29
%63 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %29 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), %30 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), %54 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), %34 ]
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* %63)
br label %4
66: ; preds = %54
ret i32 %31
}