#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 digit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *f = fopen("broevi.txt", "r");
  int i;
  while (!feof(f)) {
    int n, x;
    fscanf(f, "%d", &n);
    if (n == 0)
      break;
    int max = 0;
    int maxN = 0;
    for (i = 0; i < n; ++i) {
      fscanf(f, "%d", &x);
      int y = digit(x);
      if (y > max) {
        max = y;
        maxN = x;
      }
    }
    printf("%d\n", maxN);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a4 <main+0x44>
jmp    1246 <main+0xe6>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <fscanf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11c7 <main+0x67>
jmp    1246 <main+0xe6>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1232 <main+0xd2>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <digit@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    121f <main+0xbf>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1224 <main+0xc4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <main+0x7c>
mov    -0x24(%rbp),%esi
lea    0xdd4(%rip),%rdi
call   1040 <printf@plt>
jmp    1186 <main+0x26>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11a6 <main+0x46>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe60(%rip),%r14
mov    %rsp,%r12
jmp    11dc <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
lea    0xe47(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    118d <main+0x2d>
mov    %rbx,%rdi
mov    %r14,%rsi
lea    0x4(%rsp),%rdx
call   1060 <fscanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     118d <main+0x2d>
jle    11c0 <main+0x60>
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    120b <main+0xab>
add    $0x1,%r13d
cmp    0x4(%rsp),%r13d
jge    11c2 <main+0x62>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
mov    (%rsp),%edi
call   1050 <digit@plt>
cmp    %r15d,%eax
jle    1200 <main+0xa0>
mov    (%rsp),%ebp
mov    %eax,%r15d
jmp    1200 <main+0xa0>

LLVM IR (-O0):
@.str = [11 x i8] c"broevi.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
br label %10
10: ; preds = %41, %0
%11 = load i32*, i32** %2
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %44
15: ; preds = %10
%16 = load i32*, i32** %2
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
br label %44
21: ; preds = %15
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %3
br label %22
22: ; preds = %38, %21
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i32*, i32** %2
%28 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%29 = load i32, i32* %5
%30 = call i32 @digit(i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32, i32* %8
store i32 %35, i32* %6
%36 = load i32, i32* %5
store i32 %36, i32* %7
br label %37
37: ; preds = %34, %26
br label %38
38: ; preds = %37
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %22
41: ; preds = %22
%42 = load i32, i32* %7
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %42)
br label %10
44: ; preds = %20, %10
%45 = load i32*, i32** %2
%46 = call i32 @fclose(i32* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"broevi.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %35
6: ; preds = %0
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
br label %9
9: ; preds = %6, %30
%10 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = icmp sgt i32 %11, 0
br i1 %14, label %16, label %30
15: ; preds = %9
br label %35
16: ; preds = %13, %16
%17 = phi i32 [ %26, %16 ], [ 0, %13 ]
%18 = phi i32 [ %25, %16 ], [ 0, %13 ]
%19 = phi i32 [ %27, %16 ], [ 0, %13 ]
%20 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %2
%22 = call i32 @digit(i32 %21)
%23 = icmp sgt i32 %22, %18
%24 = load i32, i32* %2
%25 = select i1 %23, i32 %22, i32 %18
%26 = select i1 %23, i32 %24, i32 %17
%27 = add nuw nsw i32 %19, 1
%28 = load i32, i32* %1
%29 = icmp slt i32 %27, %28
br i1 %29, label %16, label %30
30: ; preds = %16, %13
%31 = phi i32 [ 0, %13 ], [ %26, %16 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = call i32 @feof(i32* %3)
%34 = icmp eq i32 %33, 0
br i1 %34, label %9, label %35
35: ; preds = %30, %0, %15
%36 = call i32 @fclose(i32* %3)
ret i32 0
}