#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 *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stringToDigitsArray(char *, int *, int);
int *readArgs(int *n, int argc, char *argv[]) {
  int loop;
  char readChar;
  int *numberAsArray;
  if (argc > 2 && atoi(argv[1]) >= 1 && atoi(argv[1]) <= 1000) {
    *n = atoi(argv[1]);
    numberAsArray = malloc(*n * sizeof(int));
    if (1 == 0)
      printf("%d digits on the display!\n", *n);
    if (argc >= 4 && 1 == 0) {
      stringToDigitsArray(argv[argc - 1], numberAsArray, *n);
      printf("Expected result: ");
      for (loop = 0; loop < *n; loop++)
        printf("%d", numberAsArray[loop]);
      printf(".\n");
    }
    stringToDigitsArray(argv[2], numberAsArray, *n);
  } else {
    if (1 == 0)
      printf("#digits: ");
    scanf("%d", n);
    numberAsArray = malloc(*n * sizeof(int));
    if (1 == 0)
      printf("initial display state: ");
    scanf("%c", &readChar);
    for (loop = 0; loop < *n; loop++) {
      scanf("%c", &readChar);
      numberAsArray[loop] = readChar - '0';
    }
  }
  return numberAsArray;
}


x86 assembly (clang, -O0):
<readArgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jle    1274 <readArgs+0x124>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
cmp    $0x1,%eax
jl     1274 <readArgs+0x124>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
cmp    $0x3e8,%eax
jg     1274 <readArgs+0x124>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x4,-0xc(%rbp)
jl     1258 <readArgs+0x108>
xor    %eax,%eax
test   $0x1,%al
jne    11df <readArgs+0x8f>
jmp    1258 <readArgs+0x108>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
call   1030 <stringToDigitsArray@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    124a <readArgs+0xfa>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1214 <readArgs+0xc4>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
call   1030 <stringToDigitsArray@plt>
jmp    12fb <readArgs+0x1ab>
mov    -0x8(%rbp),%rsi
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xd75(%rip),%rdi
lea    -0x1d(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    12f6 <readArgs+0x1a6>
lea    0xd4d(%rip),%rdi
lea    -0x1d(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x1d(%rbp),%edx
sub    $0x30,%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b5 <readArgs+0x165>
jmp    12fb <readArgs+0x1ab>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readArgs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
cmp    $0x3,%esi
jl     1192 <readArgs+0x52>
mov    %rdx,%r15
mov    0x8(%rdx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
lea    -0x1(%r12),%eax
cmp    $0x3e7,%eax
ja     1192 <readArgs+0x52>
mov    %r12d,(%r14)
mov    %r12d,%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    0x10(%r15),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
call   1030 <stringToDigitsArray@plt>
jmp    1206 <readArgs+0xc6>
lea    0xe67(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%r14),%edi
shl    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
lea    0xe4b(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,(%r14)
jle    1206 <readArgs+0xc6>
lea    0xe32(%rip),%r15
lea    0xf(%rsp),%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffd0,%eax
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
movslq (%r14),%rax
cmp    %rax,%rbx
jl     11e0 <readArgs+0xa0>
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Expected result: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c".\0A\00"
@.str.3 = [3 x i8] c"%c\00"
define i32* @readArgs(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %76
12: ; preds = %3
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
%17 = icmp sge i32 %16, 1
br i1 %17, label %18, label %76
18: ; preds = %12
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp sle i32 %22, 1000
br i1 %23, label %24, label %76
24: ; preds = %18
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = mul i64 %32, 4
%34 = trunc i64 %33 to i32
%35 = call i32* @malloc(i32 %34)
store i32* %35, i32** %9
%36 = load i32, i32* %5
%37 = icmp sge i32 %36, 4
br i1 %37, label %38, label %68
38: ; preds = %24
br i1 false, label %39, label %68
39: ; preds = %38
%40 = load i8**, i8*** %6
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
%46 = load i32*, i32** %9
%47 = load i32*, i32** %4
%48 = load i32, i32* %47
%49 = call i32 @stringToDigitsArray(i8* %45, i32* %46, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %51
51: ; preds = %63, %39
%52 = load i32, i32* %7
%53 = load i32*, i32** %4
%54 = load i32, i32* %53
%55 = icmp slt i32 %52, %54
br i1 %55, label %56, label %66
56: ; preds = %51
%57 = load i32*, i32** %9
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %56
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %51
66: ; preds = %51
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %66, %38, %24
%69 = load i8**, i8*** %6
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
%72 = load i32*, i32** %9
%73 = load i32*, i32** %4
%74 = load i32, i32* %73
%75 = call i32 @stringToDigitsArray(i8* %71, i32* %72, i32 %74)
br label %104
76: ; preds = %18, %12, %3
%77 = load i32*, i32** %4
%78 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %77)
%79 = load i32*, i32** %4
%80 = load i32, i32* %79
%81 = sext i32 %80 to i64
%82 = mul i64 %81, 4
%83 = trunc i64 %82 to i32
%84 = call i32* @malloc(i32 %83)
store i32* %84, i32** %9
%85 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
store i32 0, i32* %7
br label %86
86: ; preds = %100, %76
%87 = load i32, i32* %7
%88 = load i32*, i32** %4
%89 = load i32, i32* %88
%90 = icmp slt i32 %87, %89
br i1 %90, label %91, label %103
91: ; preds = %86
%92 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%93 = load i8, i8* %8
%94 = sext i8 %93 to i32
%95 = sub nsw i32 %94, 48
%96 = load i32*, i32** %9
%97 = load i32, i32* %7
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %96, i64 %98
store i32 %95, i32* %99
br label %100
100: ; preds = %91
%101 = load i32, i32* %7
%102 = add nsw i32 %101, 1
store i32 %102, i32* %7
br label %86
103: ; preds = %86
br label %104
104: ; preds = %103, %68
%105 = load i32*, i32** %9
ret i32* %105
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [3 x i8] c"%c\00"
define i32* @readArgs(i32* %0, i32 %1, i8** nocapture %2) {
%4 = alloca i8
%5 = icmp sgt i32 %1, 2
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = getelementptr inbounds i8*, i8** %2, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = add i32 %9, -1
%11 = icmp ult i32 %10, 1000
br i1 %11, label %12, label %18
12: ; preds = %6
store i32 %9, i32* %0
%13 = shl nuw nsw i32 %9, 2
%14 = tail call i32* @malloc(i32 %13)
%15 = getelementptr inbounds i8*, i8** %2, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @stringToDigitsArray(i8* %16, i32* %14, i32 %9)
br label %37
18: ; preds = %6, %3
%19 = tail call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %0)
%20 = load i32, i32* %0
%21 = shl i32 %20, 2
%22 = tail call i32* @malloc(i32 %21)
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%24 = load i32, i32* %0
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %18, %26
%27 = phi i64 [ %33, %26 ], [ 0, %18 ]
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = add nsw i32 %30, -48
%32 = getelementptr inbounds i32, i32* %22, i64 %27
store i32 %31, i32* %32
%33 = add nuw nsw i64 %27, 1
%34 = load i32, i32* %0
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %26, label %37
37: ; preds = %26, %18, %12
%38 = phi i32* [ %14, %12 ], [ %22, %18 ], [ %22, %26 ]
ret i32* %38
}