#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 scalar_t__ int8_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
char *strtok(char *, char *);
scalar_t__ strtol(char *, char **, int);
int parse_int8_t_array(char *s, int8_t *arr, int n) {
  char *line, *endptr;
  int i = 0;
  int8_t v;
  assert(s != NULL && "Invalid input string");
  line = strtok(s, "\n");
  while (line != NULL && i < n) {
    endptr = line;
    v = (int8_t)(strtol(line, &endptr, 10));
    if ((*endptr) != (char)0) {
      fprintf(stderr, "Invalid input: line %d of section\n", i);
    }
    arr[i] = v;
    i++;
    line[strlen(line)] = '\n';
    line = strtok(NULL, "\n");
  }
  if (line != NULL) {
    line[strlen(line)] = '\n';
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_int8_t_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x39(%rbp)
je     1184 <parse_int8_t_array+0x34>
mov    $0x1,%al
mov    %al,-0x39(%rbp)
jmp    1184 <parse_int8_t_array+0x34>
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x3a(%rbp)
je     11c1 <parse_int8_t_array+0x71>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    11d1 <parse_int8_t_array+0x81>
jmp    1265 <parse_int8_t_array+0x115>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1217 <parse_int8_t_array+0xc7>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe03(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xddf(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11a5 <parse_int8_t_array+0x55>
cmpq   $0x0,-0x20(%rbp)
je     128c <parse_int8_t_array+0x13c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int8_t_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1040 <assert@plt>
lea    0xea9(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
setne  %al
je     1206 <parse_int8_t_array+0xb6>
test   %ebx,%ebx
jle    1206 <parse_int8_t_array+0xb6>
mov    %ebx,%r12d
xor    %ebx,%ebx
lea    0xe86(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15,(%rsp)
mov    %r15,%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11d7 <parse_int8_t_array+0x87>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    %rbp,(%r14,%rbx,8)
mov    %r15,%rdi
call   1030 <strlen@plt>
movb   $0xa,(%r15,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
setne  %al
je     1206 <parse_int8_t_array+0xb6>
add    $0x1,%rbx
cmp    %r12,%rbx
jb     11a0 <parse_int8_t_array+0x50>
test   %al,%al
je     1217 <parse_int8_t_array+0xc7>
mov    %r15,%rdi
call   1030 <strlen@plt>
movb   $0xa,(%r15,%rax,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Invalid input string\00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Invalid input: line %d of section\0A\00"
define i32 @parse_int8_t_array(i8* %0, i64* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
store i32 0, i32* %9
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %14
14: ; preds = %13, %3
%15 = phi i1 [ false, %3 ], [ true, %13 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %4
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %7
br label %20
20: ; preds = %41, %14
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %54
29: ; preds = %27
%30 = load i8*, i8** %7
store i8* %30, i8** %8
%31 = load i8*, i8** %7
%32 = call i64 @strtol(i8* %31, i8** %8, i32 10)
store i64 %32, i64* %10
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i32, i32* %9
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %29
%42 = load i64, i64* %10
%43 = load i64*, i64** %5
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i64, i64* %43, i64 %45
store i64 %42, i64* %46
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
%49 = load i8*, i8** %7
%50 = load i8*, i8** %7
%51 = call i64 @strlen(i8* %50)
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 10, i8* %52
%53 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %7
br label %20
54: ; preds = %27
%55 = load i8*, i8** %7
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i8*, i8** %7
%59 = load i8*, i8** %7
%60 = call i64 @strlen(i8* %59)
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 10, i8* %61
br label %62
62: ; preds = %57, %54
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"Invalid input: line %d of section\0A\00"
define i32 @parse_int8_t_array(i8* %0, i64* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp ne i8* %9, null
%11 = icmp sgt i32 %2, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %3
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %26
%16 = phi i64 [ 0, %13 ], [ %28, %26 ]
%17 = phi i8* [ %9, %13 ], [ %31, %26 ]
store i8* %17, i8** %4
%18 = call i64 @strtol(i8* %17, i8** %4, i32 10)
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = trunc i64 %16 to i32
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %15
%27 = getelementptr inbounds i64, i64* %1, i64 %16
store i64 %18, i64* %27
%28 = add nuw nsw i64 %16, 1
%29 = tail call i64 @strlen(i8* %17)
%30 = getelementptr inbounds i8, i8* %17, i64 %29
store i8 10, i8* %30
%31 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp ne i8* %31, null
%33 = icmp ult i64 %28, %14
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %15, label %35
35: ; preds = %26, %3
%36 = phi i8* [ %9, %3 ], [ %31, %26 ]
%37 = phi i1 [ %10, %3 ], [ %32, %26 ]
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = tail call i64 @strlen(i8* %36)
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 10, i8* %40
br label %41
41: ; preds = %38, %35
ret i32 0
}