#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 atoi(char *);
int findNdigits(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int n, i, maxdigits, maxdigitsi, ndigits;
  if (argc != 2) {
    printf("ERROR: invalid or missing argument\n");
    printf("USAGE: %s n\n", argv[0]);
    return (1);
  }
  n = atoi(argv[1]);
  if (n % 2 == 0 || n % 5 == 0) {
    printf("ERROR: Invalid argument.  n must not be divisible by 2 or 5.\n");
    return (1);
  }
  if (n < 0) {
    maxdigits = 0;
    maxdigitsi = 0;
    for (i = 1; i < -n; i++) {
      if (i % 2 != 0 && i % 5 != 0) {
        ndigits = findNdigits(i);
        printf("%6d: %d\n", i, ndigits);
        if (maxdigits < ndigits) {
          maxdigits = ndigits;
          maxdigitsi = i;
        }
      }
    }
    printf("max ndigits = %d for n = %d\n", maxdigits, maxdigitsi);
  } else {
    ndigits = findNdigits(n);
    printf("%6d: %d\n", n, ndigits);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117f <main+0x4f>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b7 <main+0x87>
mov    -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d1 <main+0xa1>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <main+0x186>
cmpl   $0x0,-0x14(%rbp)
jge    1290 <main+0x160>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
xor    %ecx,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1277 <main+0x147>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1264 <main+0x134>
mov    -0x18(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1264 <main+0x134>
mov    -0x18(%rbp),%edi
call   1040 <findNdigits@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125f <main+0x12f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1264 <main+0x134>
jmp    1269 <main+0x139>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f0 <main+0xc0>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12af <main+0x17f>
mov    -0x14(%rbp),%edi
call   1040 <findNdigits@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%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
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11a2 <main+0x62>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
test   $0x1,%bpl
je     11ca <main+0x8a>
movslq %ebp,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
je     11ca <main+0x8a>
test   %ebp,%ebp
js     11e1 <main+0xa1>
mov    %ebp,%edi
call   1050 <findNdigits@plt>
lea    0xe77(%rip),%rdi
xor    %r14d,%r14d
mov    %ebp,%esi
mov    %eax,%edx
jmp    1281 <main+0x141>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    1288 <main+0x148>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    1288 <main+0x148>
xor    %r14d,%r14d
mov    $0x0,%r13d
mov    $0x0,%r15d
cmp    $0xffffffff,%ebp
je     1274 <main+0x134>
neg    %ebp
cmp    $0x3,%ebp
mov    $0x2,%r12d
cmovge %ebp,%r12d
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    1228 <main+0xe8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%r12d
je     1274 <main+0x134>
test   $0x1,%bpl
je     1220 <main+0xe0>
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
neg    %eax
add    %ebp,%eax
add    $0x1,%eax
cmp    $0x1,%eax
je     1220 <main+0xe0>
mov    %ebp,%edi
call   1050 <findNdigits@plt>
mov    %eax,%ebx
lea    0xdb1(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebx,%r13d
cmovl  %ebx,%r13d
cmovl  %ebp,%r15d
jmp    1220 <main+0xe0>
lea    0xd9b(%rip),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"ERROR: invalid or missing argument\0A\00"
@.str.1 = [13 x i8] c"USAGE: %s n\0A\00"
@.str.2 = [62 x i8] c"ERROR: Invalid argument. n must not be divisible by 2 or 5.\0A\00"
@.str.3 = [9 x i8] c"%6d: %d\0A\00"
@.str.4 = [29 x i8] c"max ndigits = %d for n = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %78
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = srem i32 %24, 2
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = srem i32 %28, 5
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27, %19
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %78
33: ; preds = %27
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %71
36: ; preds = %33
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %7
br label %37
37: ; preds = %64, %36
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = sub nsw i32 0, %39
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %67
42: ; preds = %37
%43 = load i32, i32* %7
%44 = srem i32 %43, 2
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %63
46: ; preds = %42
%47 = load i32, i32* %7
%48 = srem i32 %47, 5
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = load i32, i32* %7
%52 = call i32 @findNdigits(i32 %51)
store i32 %52, i32* %10
%53 = load i32, i32* %7
%54 = load i32, i32* %10
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %53, i32 %54)
%56 = load i32, i32* %8
%57 = load i32, i32* %10
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %62
59: ; preds = %50
%60 = load i32, i32* %10
store i32 %60, i32* %8
%61 = load i32, i32* %7
store i32 %61, i32* %9
br label %62
62: ; preds = %59, %50
br label %63
63: ; preds = %62, %46, %42
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %37
67: ; preds = %37
%68 = load i32, i32* %8
%69 = load i32, i32* %9
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %68, i32 %69)
br label %77
71: ; preds = %33
%72 = load i32, i32* %6
%73 = call i32 @findNdigits(i32 %72)
store i32 %73, i32* %10
%74 = load i32, i32* %6
%75 = load i32, i32* %10
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %75)
br label %77
77: ; preds = %71, %67
store i32 0, i32* %3
br label %78
78: ; preds = %77, %31, %13
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"USAGE: %s n\0A\00"
@.str.3 = [9 x i8] c"%6d: %d\0A\00"
@.str.4 = [29 x i8] c"max ndigits = %d for n = %d\0A\00"
@str = [61 x i8] c"ERROR: Invalid argument. n must not be divisible by 2 or 5.\00"
@str.5 = [35 x i8] c"ERROR: invalid or missing argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %53
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = and i32 %11, 1
%13 = icmp eq i32 %12, 0
%14 = srem i32 %11, 5
%15 = icmp eq i32 %14, 0
%16 = or i1 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
br label %53
19: ; preds = %8
%20 = icmp slt i32 %11, 0
br i1 %20, label %21, label %50
21: ; preds = %19
%22 = icmp eq i32 %11, -1
br i1 %22, label %46, label %23
23: ; preds = %21
%24 = sub i32 0, %11
%25 = call i32 @llvm.smax.i32(i32 %24, i32 2)
br label %26
26: ; preds = %23, %41
%27 = phi i32 [ %43, %41 ], [ 0, %23 ]
%28 = phi i32 [ %42, %41 ], [ 0, %23 ]
%29 = phi i32 [ %44, %41 ], [ 1, %23 ]
%30 = and i32 %29, 1
%31 = icmp eq i32 %30, 0
%32 = urem i32 %29, 5
%33 = icmp eq i32 %32, 0
%34 = or i1 %31, %33
br i1 %34, label %41, label %35
35: ; preds = %26
%36 = tail call i32 @findNdigits(i32 %29)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %36)
%38 = icmp slt i32 %28, %36
%39 = select i1 %38, i32 %36, i32 %28
%40 = select i1 %38, i32 %29, i32 %27
br label %41
41: ; preds = %35, %26
%42 = phi i32 [ %28, %26 ], [ %39, %35 ]
%43 = phi i32 [ %27, %26 ], [ %40, %35 ]
%44 = add nuw nsw i32 %29, 1
%45 = icmp eq i32 %44, %25
br i1 %45, label %46, label %26
46: ; preds = %41, %21
%47 = phi i32 [ 0, %21 ], [ %42, %41 ]
%48 = phi i32 [ 0, %21 ], [ %43, %41 ]
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %48)
br label %53
50: ; preds = %19
%51 = tail call i32 @findNdigits(i32 %11)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %51)
br label %53
53: ; preds = %46, %50, %17, %4
%54 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %50 ], [ 0, %46 ]
ret i32 %54
}