#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int read_network(int *hostrate) {
  FILE *fp;
  int i, numhost = 0;
  char line[100];
  i = 0;
  printf(" network file \n");
  fp = fopen("network.ntw", "r");
  while (fgets(line, 10, fp) != NULL) {
    if (i == 0) {
      sscanf(line, "%3d", &numhost);
    } else {
      sscanf(line, "%3d", &hostrate[i]);
    }
    i++;
  }
  if (numhost != (i - 2)) {
    printf("missing host in network.ntw ; numhost=%d total lines=%d   \n",
           numhost, i);
    exit(0);
  }
  fclose(fp);
  printf(" network file read completed \n");
  return numhost;
}


x86 assembly (clang, -O0):
<read_network>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120e <read_network+0xae>
cmpl   $0x0,-0x14(%rbp)
jne    11e1 <read_network+0x81>
lea    -0x80(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
jmp    1200 <read_network+0xa0>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe23(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a2 <read_network+0x42>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
je     123a <read_network+0xda>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_network>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r15
movl   $0x0,0xc(%rsp)
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe62(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     123c <read_network+0xcc>
lea    0xe43(%rip),%rsi
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1242 <read_network+0xd2>
add    $0x4,%r15
mov    $0x1,%ebx
lea    0xe0c(%rip),%r12
lea    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
mov    %r13,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x4,%r15
add    $0x1,%ebx
test   %rax,%rax
jne    1210 <read_network+0xa0>
jmp    1247 <read_network+0xd7>
xor    %esi,%esi
xor    %ebx,%ebx
jmp    124b <read_network+0xdb>
mov    $0x1,%ebx
mov    0xc(%rsp),%esi
lea    -0x2(%rbx),%eax
cmp    %eax,%esi
jne    127b <read_network+0x10b>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd90(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c" network file \0A\00"
@.str.1 = [12 x i8] c"network.ntw\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%3d\00"
@.str.4 = [60 x i8] c"missing host in network.ntw ; numhost=%d total lines=%d \0A\00"
@.str.5 = [31 x i8] c" network file read completed \0A\00"
define i32 @read_network(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
store i32* %0, i32** %2
store i32 0, i32* %5
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %3
br label %9
9: ; preds = %27, %1
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32* @fgets(i8* %10, i32 10, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %5)
br label %27
20: ; preds = %14
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %20, %17
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %9
30: ; preds = %9
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 2
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %37)
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %30
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"network.ntw\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%3d\00"
@.str.4 = [60 x i8] c"missing host in network.ntw ; numhost=%d total lines=%d \0A\00"
@str = [15 x i8] c" network file \00"
@str.6 = [30 x i8] c" network file read completed \00"
define i32 @read_network(i32* %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32* @fgets(i8* %5, i32 10, i32* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %26, label %10
10: ; preds = %1
%11 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%12 = call i32* @fgets(i8* %5, i32 10, i32* %7)
%13 = icmp eq i32* %12, null
br i1 %13, label %23, label %14
14: ; preds = %10, %14
%15 = phi i64 [ %18, %14 ], [ 1, %10 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%18 = add nuw i64 %15, 1
%19 = call i32* @fgets(i8* %5, i32 10, i32* %7)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = trunc i64 %18 to i32
br label %23
23: ; preds = %21, %10
%24 = phi i32 [ 1, %10 ], [ %22, %21 ]
%25 = load i32, i32* %2
br label %26
26: ; preds = %23, %1
%27 = phi i32 [ 0, %1 ], [ %25, %23 ]
%28 = phi i32 [ 0, %1 ], [ %24, %23 ]
%29 = add nsw i32 %28, -2
%30 = icmp eq i32 %27, %29
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %28)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %26
%35 = call i32 @fclose(i32* %7)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%37 = load i32, i32* %2
ret i32 %37
}