#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ config_device(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
void read_config(char *name) {
  FILE *f;
  char line[80];
  if (strcmp(name, "-") == 0) {
    f = stdin;
  } else if (!(f = fopen(name, "r"))) {
    perror(name);
    exit(1);
  }
  while (fgets(line, sizeof(line), f)) {
    char *device_name = strtok(line, " \t\n");
    char *remote_name = strtok(NULL, " \t\n");
    char *circuits = strtok(NULL, " \t\n");
    if (!device_name || *device_name == '#')
      continue;
    if (!remote_name) {
      fprintf(stderr, "Bad line %s in %s\n", device_name, name);
      continue;
    }
    config_device(device_name, remote_name, circuits);
  }
  if (f != stdin)
    fclose(f);
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11cc <read_config+0x3c>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1202 <read_config+0x72>
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fd <read_config+0x6d>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1202 <read_config+0x72>
jmp    1207 <read_config+0x77>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c2 <read_config+0x132>
lea    -0x60(%rbp),%rdi
lea    0xdd6(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x68(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc2(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x70(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdae(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     127a <read_config+0xea>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    127f <read_config+0xef>
jmp    1207 <read_config+0x77>
cmpq   $0x0,-0x70(%rbp)
jne    12ac <read_config+0x11c>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd66(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1207 <read_config+0x77>
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   1030 <config_device@plt>
jmp    1207 <read_config+0x77>
mov    -0x10(%rbp),%rax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%rax
je     12df <read_config+0x14f>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
lea    0xe58(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11db <read_config+0x4b>
lea    0xe49(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11e5 <read_config+0x55>
mov    %r14,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%r15
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     128a <read_config+0xfa>
lea    0xdff(%rip),%rbx
mov    %rsp,%r12
jmp    1245 <read_config+0xb5>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1070 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     128a <read_config+0xfa>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rbp
xor    %edi,%edi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %rbx,%rsi
call   10a0 <strtok@plt>
test   %rbp,%rbp
je     1230 <read_config+0xa0>
cmpb   $0x23,0x0(%rbp)
je     1230 <read_config+0xa0>
test   %r13,%r13
je     120a <read_config+0x7a>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1030 <config_device@plt>
jmp    1230 <read_config+0xa0>
mov    0x2d57(%rip),%rax
cmp    (%rax),%r15
je     129e <read_config+0x10e>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" \09\0A\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"Bad line %s in %s\0A\00"
define void @read_config(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32*, i32** @stdin
store i32* %12, i32** %3
br label %22
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = call i32 @perror(i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
br label %22
22: ; preds = %21, %11
br label %23
23: ; preds = %49, %44, %40, %22
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%25 = load i32*, i32** %3
%26 = call i64 @fgets(i8* %24, i32 80, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %54
28: ; preds = %23
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%30 = call i8* @strtok(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %30, i8** %5
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %31, i8** %6
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %32, i8** %7
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 35
br i1 %39, label %40, label %41
40: ; preds = %35, %28
br label %23
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %5
%47 = load i8*, i8** %2
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %46, i8* %47)
br label %23
49: ; preds = %41
%50 = load i8*, i8** %5
%51 = load i8*, i8** %6
%52 = load i8*, i8** %7
%53 = call i32 @config_device(i8* %50, i8* %51, i8* %52)
br label %23
54: ; preds = %23
%55 = load i32*, i32** %3
%56 = load i32*, i32** @stdin
%57 = icmp ne i32* %55, %56
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i32*, i32** %3
%60 = call i32 @fclose(i32* %59)
br label %61
61: ; preds = %58, %54
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c" \09\0A\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"Bad line %s in %s\0A\00"
define void @read_config(i8* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32*, i32** @stdin
br label %14
8: ; preds = %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %6
%15 = phi i32* [ %7, %6 ], [ %9, %8 ]
%16 = call i64 @fgets(i8* %3, i32 80, i32* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %36, label %18
18: ; preds = %14, %33
%19 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %19, null
br i1 %22, label %33, label %23
23: ; preds = %18
%24 = load i8, i8* %19
%25 = icmp eq i8 %24, 35
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = icmp eq i8* %20, null
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %0)
br label %33
31: ; preds = %26
%32 = call i32 @config_device(i8* %19, i8* %20, i8* %21)
br label %33
33: ; preds = %18, %23, %31, %28
%34 = call i64 @fgets(i8* %3, i32 80, i32* %15)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %18
36: ; preds = %33, %14
%37 = load i32*, i32** @stdin
%38 = icmp eq i32* %15, %37
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 @fclose(i32* %15)
br label %41
41: ; preds = %39, %36
ret void
}