#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *get_port_name(int n) {
  static char name[256];
  char buf[256];
  FILE *f;
  int i = 0;
  strcpy(name, "");
  f = fopen("/etc/ax25/axports", "r");
  if (f != NULL)
    while (!feof(f)) {
      strcpy(buf, "");
      if (fgets(buf, 255, f) != NULL) {
        while (isspace(*buf))
          memmove(buf, buf + 1, strlen(buf));
        if (buf[0] == '#' || strlen(buf) == 0)
          continue;
        if (i == n) {
          sscanf(buf, "%s", name);
          break;
        }
        i++;
      }
    }
  return name;
}


x86 assembly (clang, -O0):
<get_port_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x11c(%rbp)
lea    0x2ed1(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe4e(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1302 <get_port_name+0x182>
jmp    11d8 <get_port_name+0x58>
mov    -0x118(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <get_port_name+0x79>
jmp    12fd <get_port_name+0x17d>
lea    -0x110(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12f8 <get_port_name+0x178>
jmp    1233 <get_port_name+0xb3>
movsbl -0x110(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1290 <get_port_name+0x110>
lea    -0x110(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    %rax,%rdx
call   1090 <memmove@plt>
jmp    1233 <get_port_name+0xb3>
movsbl -0x110(%rbp),%eax
cmp    $0x23,%eax
je     12b6 <get_port_name+0x136>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    12bb <get_port_name+0x13b>
jmp    11d8 <get_port_name+0x58>
mov    -0x11c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    12e9 <get_port_name+0x169>
lea    -0x110(%rbp),%rdi
lea    0xd3c(%rip),%rsi
lea    0x2d91(%rip),%rdx
call   1080 <sscanf@plt>
jmp    12fd <get_port_name+0x17d>
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    11d8 <get_port_name+0x58>
jmp    1302 <get_port_name+0x182>
lea    0x2d67(%rip),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_port_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r14d
lea    0x2ed5(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe52(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11ce <get_port_name+0x4e>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11e7 <get_port_name+0x67>
lea    0x2e9b(%rip),%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
lea    0x1(%rsp),%rbp
lea    0xe1d(%rip),%r15
mov    %rsp,%rbx
jmp    120c <get_port_name+0x8c>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11ce <get_port_name+0x4e>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1200 <get_port_name+0x80>
nopl   0x0(%rax)
movsbl (%rsp),%edi
call   1050 <isspace@plt>
test   %rax,%rax
je     1260 <get_port_name+0xe0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1090 <memmove@plt>
jmp    1230 <get_port_name+0xb0>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%al
cmp    $0x23,%al
je     1200 <get_port_name+0x80>
test   %al,%al
je     1200 <get_port_name+0x80>
cmp    %r14d,%r13d
je     1276 <get_port_name+0xf6>
add    $0x1,%r13d
jmp    1200 <get_port_name+0x80>
lea    0xd97(%rip),%rsi
lea    0x2dec(%rip),%rdx
mov    %rsp,%rdi
call   1080 <sscanf@plt>
jmp    11ce <get_port_name+0x4e>

LLVM IR (-O0):
@get_port_name.name = internal global [256 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"/etc/ax25/axports\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
define i8* @get_port_name(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
%6 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 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* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %58
10: ; preds = %1
br label %11
11: ; preds = %56, %45, %10
%12 = load i32*, i32** %4
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %57
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 255, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %56
23: ; preds = %16
br label %24
24: ; preds = %29, %23
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = load i8, i8* %25
%27 = call i64 @isspace(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%34 = call i64 @strlen(i8* %33)
%35 = call i32 @memmove(i8* %30, i8* %32, i64 %34)
br label %24
36: ; preds = %24
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 35
br i1 %40, label %45, label %41
41: ; preds = %36
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41, %36
br label %11
46: ; preds = %41
%47 = load i32, i32* %5
%48 = load i32, i32* %2
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%52 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0))
br label %57
53: ; preds = %46
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %56
56: ; preds = %53, %16
br label %11
57: ; preds = %50, %11
br label %58
58: ; preds = %57, %1
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0)
}

LLVM IR (-O2):
@get_port_name.name = internal global [256 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"/etc/ax25/axports\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
define i8* @get_port_name(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %43, label %7
7: ; preds = %1
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %7
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
br label %12
12: ; preds = %10, %39
%13 = phi i32 [ 0, %10 ], [ %40, %39 ]
br label %14
14: ; preds = %12, %30
%15 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = call i32* @fgets(i8* %3, i32 255, i32* %5)
%17 = icmp eq i32* %16, null
br i1 %17, label %39, label %18
18: ; preds = %14
%19 = load i8, i8* %3
%20 = call i64 @isspace(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18, %22
%23 = call i64 @strlen(i8* %3)
%24 = call i32 @memmove(i8* %3, i8* %11, i64 %23)
%25 = load i8, i8* %3
%26 = call i64 @isspace(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %22
28: ; preds = %22, %18
%29 = load i8, i8* %3
switch i8 %29, label %33 [
i8 35, label %30
i8 0, label %30
]
30: ; preds = %28, %28
%31 = call i32 @feof(i32* %5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %14, label %43
33: ; preds = %28
%34 = icmp eq i32 %13, %0
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0))
br label %43
37: ; preds = %33
%38 = add nsw i32 %13, 1
br label %39
39: ; preds = %14, %37
%40 = phi i32 [ %38, %37 ], [ %13, %14 ]
%41 = call i32 @feof(i32* %5)
%42 = icmp eq i32 %41, 0
br i1 %42, label %12, label %43
43: ; preds = %39, %30, %7, %35, %1
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @get_port_name.name, i64 0, i64 0)
}