#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*/ str;

/* Variables and functions */
int char_to_num(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int unique_insert(int *, int, int);
int split_and_insert(char buff[], int data[]) {
  char str[1024];
  int n, i, j, ret, tmp;
  memset(str, 0, sizeof(str));
  n = 0;
  i = 0;
  j = 0;
  while (buff[i] != '\0') {
    if ('\n' == buff[i]) {
      str[j] = '\0';
      tmp = char_to_num(str);
      if (tmp > -1) {
        ret = unique_insert(data, n, tmp);
        if (ret < 0)
          printf("insert data failed\n");
        else if (ret > 0)
          n++;
        else
          ;
      } else
        printf("number invalid\n");
      j = 0;
      i++;
      continue;
    }
    str[j] = buff[i];
    j++;
    i++;
  }
  return n;
}


x86 assembly (clang, -O0):
<split_and_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x418(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12b8 <split_and_insert+0x178>
mov    -0x8(%rbp),%rax
movslq -0x418(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    1279 <split_and_insert+0x139>
movslq -0x41c(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1040 <char_to_num@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jle    124f <split_and_insert+0x10f>
mov    -0x10(%rbp),%rdi
mov    -0x414(%rbp),%esi
mov    -0x424(%rbp),%edx
call   1030 <unique_insert@plt>
mov    %eax,-0x420(%rbp)
cmpl   $0x0,-0x420(%rbp)
jge    121f <split_and_insert+0xdf>
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
jmp    124a <split_and_insert+0x10a>
cmpl   $0x0,-0x420(%rbp)
jle    1240 <split_and_insert+0x100>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1245 <split_and_insert+0x105>
jmp    1245 <split_and_insert+0x105>
jmp    124a <split_and_insert+0x10a>
jmp    125b <split_and_insert+0x11b>
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x41c(%rbp)
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1184 <split_and_insert+0x44>
mov    -0x8(%rbp),%rax
movslq -0x418(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x41c(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1184 <split_and_insert+0x44>
mov    -0x414(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_and_insert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
xor    %ebp,%ebp
movslq %ebx,%r12
lea    (%r15,%r12,1),%rax
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rax,%r13,1),%ecx
test   %cl,%cl
je     11f5 <split_and_insert+0xb5>
cmp    $0xa,%cl
je     11a0 <split_and_insert+0x60>
mov    %cl,(%rsp,%r13,1)
add    $0x1,%r13
jmp    1180 <split_and_insert+0x40>
nopl   0x0(%rax,%rax,1)
mov    %r13d,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1040 <char_to_num@plt>
test   %eax,%eax
js     11d3 <split_and_insert+0x93>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <unique_insert@plt>
test   %eax,%eax
js     11dc <split_and_insert+0x9c>
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
lea    (%r12,%r13,1),%rbx
add    $0x1,%rbx
jmp    116a <split_and_insert+0x2a>
lea    0xe26(%rip),%rdi
jmp    11e3 <split_and_insert+0xa3>
lea    0xe2c(%rip),%rdi
call   1050 <puts@plt>
lea    (%r12,%r13,1),%rbx
add    $0x1,%rbx
jmp    116a <split_and_insert+0x2a>
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"insert data failed\0A\00"
@.str.1 = [16 x i8] c"number invalid\0A\00"
define i32 @split_and_insert(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1024)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %60, %57, %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %73
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 10, %27
br i1 %28, label %29, label %60
29: ; preds = %21
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %31
store i8 0, i8* %32
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%34 = call i32 @char_to_num(i8* %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp sgt i32 %35, -1
br i1 %36, label %37, label %55
37: ; preds = %29
%38 = load i32*, i32** %4
%39 = load i32, i32* %6
%40 = load i32, i32* %10
%41 = call i32 @unique_insert(i32* %38, i32 %39, i32 %40)
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %54
46: ; preds = %37
%47 = load i32, i32* %9
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %53
52: ; preds = %46
br label %53
53: ; preds = %52, %49
br label %54
54: ; preds = %53, %44
br label %57
55: ; preds = %29
%56 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %57
57: ; preds = %55, %54
store i32 0, i32* %8
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %13
60: ; preds = %21
%61 = load i8*, i8** %3
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %67
store i8 %65, i8* %68
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %13
73: ; preds = %13
%74 = load i32, i32* %6
ret i32 %74
}

LLVM IR (-O2):
@str = [15 x i8] c"number invalid\00"
@str.2 = [19 x i8] c"insert data failed\00"
define i32 @split_and_insert(i8* nocapture %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
br label %6
6: ; preds = %32, %2
%7 = phi i64 [ %34, %32 ], [ 0, %2 ]
%8 = phi i32 [ %33, %32 ], [ 0, %2 ]
%9 = shl i64 %7, 32
%10 = ashr exact i64 %9, 32
br label %11
11: ; preds = %6, %35
%12 = phi i64 [ %10, %6 ], [ %38, %35 ]
%13 = phi i64 [ 0, %6 ], [ %37, %35 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = load i8, i8* %14
switch i8 %15, label %35 [
i8 0, label %39
i8 10, label %16
]
16: ; preds = %11
%17 = and i64 %13, 4294967295
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @char_to_num(i8* %4)
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = call i32 @unique_insert(i32* %1, i32 %8, i32 %19)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %32
26: ; preds = %21
%27 = icmp ne i32 %22, 0
%28 = zext i1 %27 to i32
%29 = add nsw i32 %8, %28
br label %32
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %26, %24, %30
%33 = phi i32 [ %8, %24 ], [ %8, %30 ], [ %29, %26 ]
%34 = add i64 %12, 1
br label %6
35: ; preds = %11
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %13
store i8 %15, i8* %36
%37 = add nuw i64 %13, 1
%38 = add i64 %12, 1
br label %11
39: ; preds = %11
ret i32 %8
}