#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, j, numhost = 0;
  char line[100];
  i = 0;
  j = 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[j]);
      j++;
    }
    i++;
  }
  if (numhost != (i - 1)) {
    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,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe77(%rip),%rdi
lea    0xe7c(%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     121e <read_network+0xbe>
cmpl   $0x0,-0x14(%rbp)
jne    11e8 <read_network+0x88>
lea    -0x80(%rbp),%rdi
lea    0xe44(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
jmp    1210 <read_network+0xb0>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe1c(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a9 <read_network+0x49>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     124a <read_network+0xea>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xde6(%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    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%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     1240 <read_network+0xd0>
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>
mov    $0x1,%ebx
test   %rax,%rax
je     123a <read_network+0xca>
lea    0xe10(%rip),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
add    $0x1,%ebx
mov    %r13,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x4,%r15
test   %rax,%rax
jne    1210 <read_network+0xa0>
mov    0xc(%rsp),%esi
jmp    1244 <read_network+0xd4>
xor    %esi,%esi
xor    %ebx,%ebx
lea    -0x1(%rbx),%eax
cmp    %eax,%esi
jne    1274 <read_network+0x104>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe03(%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    0xd97(%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 i32
%7 = alloca [100 x i8]
store i32* %0, i32** %2
store i32 0, i32* %6
store i32 0, i32* %4
store i32 0, i32* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = 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* %9, i32** %3
br label %10
10: ; preds = %30, %1
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i32* @fgets(i8* %11, i32 10, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %30
21: ; preds = %15
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = load i32*, i32** %2
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %26)
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %30
30: ; preds = %21, %18
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %10
33: ; preds = %10
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* %6
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %33
%44 = load i32*, i32** %3
%45 = call i32 @fclose(i32* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* %6
ret i32 %47
}

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 %27, 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 %24, label %14
14: ; preds = %10, %14
%15 = phi i32 [ %20, %14 ], [ 0, %10 ]
%16 = phi i32 [ %21, %14 ], [ 1, %10 ]
%17 = zext i32 %15 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i32 %15, 1
%21 = add nuw nsw i32 %16, 1
%22 = call i32* @fgets(i8* %5, i32 10, i32* %7)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %14
24: ; preds = %14, %10
%25 = phi i32 [ 1, %10 ], [ %21, %14 ]
%26 = load i32, i32* %2
br label %27
27: ; preds = %24, %1
%28 = phi i32 [ 0, %1 ], [ %26, %24 ]
%29 = phi i32 [ 0, %1 ], [ %25, %24 ]
%30 = add nsw i32 %29, -1
%31 = icmp eq i32 %28, %30
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %29)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27
%36 = call i32 @fclose(i32* %7)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%38 = load i32, i32* %2
ret i32 %38
}