#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_color_set_from_file(const char *file_path, char color_set[][7]) {
  int i;
  FILE *fd;
  char *line = NULL, *color = NULL;
  size_t read = 0;
  if ((fd = fopen(file_path, "r")) == NULL)
    return -1;
  for (i = 0; getline(&line, &read, fd) > 0; ++i) {
    if (!color_set[i])
      break;
    color = line;
    if (color[0] == '\n') {
      --i;
      continue;
    }
    if (color[0] == '#')
      ++color;
    sscanf(color, "%d#%s", &i, color);
    if (i >= 16)
      continue;
    if (strlen(color) < 6) {
      fprintf(stderr, "Color %d: value too short, skipping\n", i);
      continue;
    }
    strncpy(color_set[i], color, 6);
  }
  if (i < 16)
    fprintf(stderr, "Warning: Less than 16 colors in configuration\n");
  if (line)
    free(line);
  fclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<get_color_set_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11d2 <get_color_set_from_file+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <get_color_set_from_file+0x19c>
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0x0,%rax
jle    12d7 <get_color_set_from_file+0x157>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x7,%rcx,%rcx
add    %rcx,%rax
cmp    $0x0,%rax
jne    1212 <get_color_set_from_file+0x92>
jmp    12d7 <get_color_set_from_file+0x157>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1238 <get_color_set_from_file+0xb8>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c9 <get_color_set_from_file+0x149>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1254 <get_color_set_from_file+0xd4>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x38(%rbp),%rcx
lea    0xd9f(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <sscanf@plt>
cmpl   $0x10,-0x1c(%rbp)
jl     127b <get_color_set_from_file+0xfb>
jmp    12c9 <get_color_set_from_file+0x149>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x6,%eax
jge    12ac <get_color_set_from_file+0x12c>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12c9 <get_color_set_from_file+0x149>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
imul   $0x7,%rax,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
mov    $0x6,%edx
call   1040 <strncpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d9 <get_color_set_from_file+0x59>
cmpl   $0x10,-0x1c(%rbp)
jge    12f8 <get_color_set_from_file+0x178>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
je     130c <get_color_set_from_file+0x18c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_color_set_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe56(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c2 <get_color_set_from_file+0x142>
mov    %rax,%r14
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    12ce <get_color_set_from_file+0x14e>
lea    0x4(%rsp),%r12
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%r13
xor    %ecx,%ecx
jmp    1227 <get_color_set_from_file+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ecx
mov    %ecx,0x4(%rsp)
addl   $0x1,0x4(%rsp)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   10a0 <getline@plt>
mov    0x4(%rsp),%ecx
test   %rax,%rax
jle    12c9 <get_color_set_from_file+0x149>
test   %rbx,%rbx
je     12c9 <get_color_set_from_file+0x149>
mov    0x8(%rsp),%r15
movzbl (%r15),%eax
cmp    $0x23,%al
je     1250 <get_color_set_from_file+0xd0>
cmp    $0xa,%al
je     1200 <get_color_set_from_file+0x80>
jmp    1254 <get_color_set_from_file+0xd4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
mov    %r15,%rdi
lea    0xda4(%rip),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1080 <sscanf@plt>
cmpl   $0xf,0x4(%rsp)
jg     1207 <get_color_set_from_file+0x87>
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    $0x5,%eax
jg     129d <get_color_set_from_file+0x11d>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    0x4(%rsp),%edx
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1207 <get_color_set_from_file+0x87>
movslq 0x4(%rsp),%rax
lea    0x0(,%rax,8),%rdi
sub    %rax,%rdi
add    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1040 <strncpy@plt>
jmp    1207 <get_color_set_from_file+0x87>
mov    $0xffffffff,%eax
jmp    12fe <get_color_set_from_file+0x17e>
cmp    $0xf,%ecx
jg     12e5 <get_color_set_from_file+0x165>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12f4 <get_color_set_from_file+0x174>
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d#%s\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Color %d: value too short, skipping\0A\00"
@.str.3 = [47 x i8] c"Warning: Less than 16 colors in configuration\0A\00"
define i32 @get_color_set_from_file(i8* %0, [7 x i8]* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [7 x i8]*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store [7 x i8]* %1, [7 x i8]** %5
store i8* null, i8** %8
store i8* null, i8** %9
store i64 0, i64* %10
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %88
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %70, %15
%17 = load i32*, i32** %7
%18 = call i64 @getline(i8** %8, i64* %10, i32* %17)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %73
20: ; preds = %16
%21 = load [7 x i8]*, [7 x i8]** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [7 x i8], [7 x i8]* %21, i64 %23
%25 = getelementptr inbounds [7 x i8], [7 x i8]* %24, i64 0, i64 0
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %20
br label %73
28: ; preds = %20
%29 = load i8*, i8** %8
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* %6
%37 = add nsw i32 %36, -1
store i32 %37, i32* %6
br label %70
38: ; preds = %28
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 35
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
br label %47
47: ; preds = %44, %38
%48 = load i8*, i8** %9
%49 = load i8*, i8** %9
%50 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %49)
%51 = load i32, i32* %6
%52 = icmp sge i32 %51, 16
br i1 %52, label %53, label %54
53: ; preds = %47
br label %70
54: ; preds = %47
%55 = load i8*, i8** %9
%56 = call i32 @strlen(i8* %55)
%57 = icmp slt i32 %56, 6
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i32, i32* %6
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %70
62: ; preds = %54
%63 = load [7 x i8]*, [7 x i8]** %5
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [7 x i8], [7 x i8]* %63, i64 %65
%67 = getelementptr inbounds [7 x i8], [7 x i8]* %66, i64 0, i64 0
%68 = load i8*, i8** %9
%69 = call i32 @strncpy(i8* %67, i8* %68, i32 6)
br label %70
70: ; preds = %62, %58, %53, %35
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
br label %16
73: ; preds = %27, %16
%74 = load i32, i32* %6
%75 = icmp slt i32 %74, 16
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %79
79: ; preds = %76, %73
%80 = load i8*, i8** %8
%81 = icmp ne i8* %80, null
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
br label %85
85: ; preds = %82, %79
%86 = load i32*, i32** %7
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %14
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d#%s\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Color %d: value too short, skipping\0A\00"
@.str.3 = [47 x i8] c"Warning: Less than 16 colors in configuration\0A\00"
define i32 @get_color_set_from_file(i8* nocapture %0, [7 x i8]* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %61, label %11
11: ; preds = %2
store i32 0, i32* %3
%12 = call i64 @getline(i8** %4, i64* %5, i32* %9)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %51
14: ; preds = %11
%15 = icmp eq [7 x i8]* %1, null
br label %16
16: ; preds = %42, %14
%17 = phi i32 [ 0, %14 ], [ %47, %42 ]
br i1 %15, label %48, label %18
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
switch i8 %20, label %25 [
i8 10, label %21
i8 35, label %23
]
21: ; preds = %18
%22 = add nsw i32 %17, -1
store i32 %22, i32* %3
br label %42
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %19, i64 1
br label %25
25: ; preds = %18, %23
%26 = phi i8* [ %24, %23 ], [ %19, %18 ]
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %26)
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 15
br i1 %29, label %42, label %30
30: ; preds = %25
%31 = call i32 @strlen(i8* %26)
%32 = icmp slt i32 %31, 6
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = load i32, i32* %3
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %42
37: ; preds = %30
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 %39, i64 0
%41 = call i32 @strncpy(i8* %40, i8* %26, i32 6)
br label %42
42: ; preds = %25, %37, %33, %21
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
%45 = call i64 @getline(i8** %4, i64* %5, i32* %9)
%46 = icmp sgt i64 %45, 0
%47 = load i32, i32* %3
br i1 %46, label %16, label %48
48: ; preds = %16, %42
%49 = phi i32 [ %47, %42 ], [ %17, %16 ]
%50 = icmp slt i32 %49, 16
br i1 %50, label %51, label %54
51: ; preds = %11, %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %51, %48
%55 = load i8*, i8** %4
%56 = icmp eq i8* %55, null
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @free(i8* %55)
br label %59
59: ; preds = %57, %54
%60 = call i32 @fclose(i32* %9)
br label %61
61: ; preds = %2, %59
%62 = phi i32 [ 0, %59 ], [ -1, %2 ]
ret i32 %62
}