#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 getNumBulls(int, int);
int getNumCows(int, int);
scalar_t__ isValidNum(int);
int /*<<< orphan*/ printBullsAndCows(int, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int target = 0, guess = 0, bulls = 0, cows = 0;
  do {
    srand(time(NULL));
    target = rand() % (9999 - 1000);
  } while (isValidNum(target) == 0);
  while (bulls != 4) {
    printf("Enter your guess.\n");
    scanf("%d", &guess);
    while (isValidNum(guess) == 0) {
      printf("\nInvalid guess! Please enter a number between 1000 and 9999, "
             "with four different digits.\n\n");
      scanf("%d", &guess);
    }
    bulls = getNumBulls(target, guess);
    cows = getNumCows(target, guess);
    printBullsAndCows(bulls, cows);
  }
  if (bulls == 4) {
    printf("Congratulations! Your guess is correct.\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x2327,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <isValidNum@plt>
cmp    $0x0,%rax
je     11bb <main+0x2b>
jmp    11f4 <main+0x64>
cmpl   $0x4,-0x10(%rbp)
je     1279 <main+0xe9>
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
lea    0xe02(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1040 <isValidNum@plt>
cmp    $0x0,%rax
jne    124d <main+0xbd>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
lea    0xdd4(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
jmp    121a <main+0x8a>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <getNumBulls@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <getNumCows@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10a0 <printBullsAndCows@plt>
jmp    11f4 <main+0x64>
cmpl   $0x4,-0x10(%rbp)
jne    128f <main+0xff>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x3a42bcf3,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2b,%rax
add    %ecx,%eax
imul   $0x2327,%eax,%eax
sub    %eax,%ebx
mov    %ebx,%edi
call   1040 <isValidNum@plt>
test   %rax,%rax
je     11b0 <main+0x20>
lea    0xe35(%rip),%r14
lea    0xe02(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xe34(%rip),%r13
jmp    1236 <main+0xa6>
nopl   0x0(%rax)
mov    0x4(%rsp),%esi
mov    %ebx,%edi
call   1080 <getNumBulls@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%esi
mov    %ebx,%edi
call   1050 <getNumCows@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   10a0 <printBullsAndCows@plt>
cmp    $0x4,%ebp
je     1263 <main+0xd3>
mov    %r14,%rdi
nopl   0x0(%rax)
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
call   1040 <isValidNum@plt>
test   %rax,%rax
jne    1210 <main+0x80>
mov    %r13,%rdi
jmp    1240 <main+0xb0>
lea    0xd99(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter your guess.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [91 x i8] c"\0AInvalid guess! Please enter a number between 1000 and 9999, with four different digits.\0A\0A\00"
@.str.3 = [42 x i8] c"Congratulations! Your guess is correct.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %11, %0
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 8999
store i32 %10, i32* %2
br label %11
11: ; preds = %6
%12 = load i32, i32* %2
%13 = call i64 @isValidNum(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %6, label %15
15: ; preds = %11
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 4
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %22
22: ; preds = %26, %19
%23 = load i32, i32* %3
%24 = call i64 @isValidNum(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %22
29: ; preds = %22
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = call i32 @getNumBulls(i32 %30, i32 %31)
store i32 %32, i32* %4
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @getNumCows(i32 %33, i32 %34)
store i32 %35, i32* %5
%36 = load i32, i32* %4
%37 = load i32, i32* %5
%38 = call i32 @printBullsAndCows(i32 %36, i32 %37)
br label %16
39: ; preds = %16
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 4
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [41 x i8] c"Congratulations! Your guess is correct.\0A\00"
@str.4 = [18 x i8] c"Enter your guess.\00"
@str.5 = [90 x i8] c"\0AInvalid guess! Please enter a number between 1000 and 9999, with four different digits.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %3
3: ; preds = %3, %0
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 8999
%8 = tail call i64 @isValidNum(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %3, label %10
10: ; preds = %3, %22
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = call i64 @isValidNum(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10, %16
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str.5, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%19 = load i32, i32* %1
%20 = call i64 @isValidNum(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %16, label %22
22: ; preds = %16, %10
%23 = load i32, i32* %1
%24 = call i32 @getNumBulls(i32 %7, i32 %23)
%25 = load i32, i32* %1
%26 = call i32 @getNumCows(i32 %7, i32 %25)
%27 = call i32 @printBullsAndCows(i32 %24, i32 %26)
%28 = icmp eq i32 %24, 4
br i1 %28, label %29, label %10
29: ; preds = %22
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
ret i32 0
}