#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *, int *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int read_etc_messip(char *hostname, int *port_used, int *port_http_used) {
  char line[512], host[80], path[80];
  size_t len;
  int port, port_http;
  strcpy(hostname, "localhost");
  FILE *fp = fopen("/usr/etc/messip", "r");
  if (fp == NULL) {
    fprintf(stderr, "Unable to open /usr/etc/messip - errno=%d\n", errno);
    return -1;
  }
  *port_used = -1;
  if (port_http_used != NULL)
    *port_http_used = -1;
  int first = 1;
  while (fgets(line, sizeof(line) - 1, fp)) {
    if (((len = strlen(line)) >= 1) && (line[len - 1] == '\n'))
      line[len - 1] = 0;
    if (!strcmp(line, "") || (line[0] == '#'))
      continue;
    sscanf(line, "%s %d %d %s", host, &port, &port_http, path);
    {
      strcpy(hostname, host);
      *port_used = port;
      if (port_http_used != NULL)
        *port_http_used = port_http;
    }
    first = 0;
  }
  if (first) {
    fprintf(stderr, "No hostname in /usr/etc/messip\n");
    return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<read_etc_messip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe5c(%rip),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x2d8(%rbp)
cmpq   $0x0,-0x2d8(%rbp)
jne    11fb <read_etc_messip+0x7b>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1377 <read_etc_messip+0x1f7>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     121a <read_etc_messip+0x9a>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x2dc(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x2d8(%rbp),%rdx
mov    $0x1ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1334 <read_etc_messip+0x1b4>
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x2c8(%rbp)
cmp    $0x1,%rax
jb     1292 <read_etc_messip+0x112>
mov    -0x2c8(%rbp),%rax
sub    $0x1,%rax
movsbl -0x220(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1292 <read_etc_messip+0x112>
mov    -0x2c8(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12be <read_etc_messip+0x13e>
movsbl -0x220(%rbp),%eax
cmp    $0x23,%eax
jne    12c3 <read_etc_messip+0x143>
jmp    1224 <read_etc_messip+0xa4>
lea    -0x220(%rbp),%rdi
lea    -0x270(%rbp),%rdx
lea    -0x2c0(%rbp),%r9
lea    0xd68(%rip),%rsi
lea    -0x2cc(%rbp),%rcx
lea    -0x2d0(%rbp),%r8
call   1090 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x270(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x2cc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1325 <read_etc_messip+0x1a5>
mov    -0x2d0(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x2dc(%rbp)
jmp    1224 <read_etc_messip+0xa4>
cmpl   $0x0,-0x2dc(%rbp)
je     1364 <read_etc_messip+0x1e4>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1377 <read_etc_messip+0x1f7>
mov    -0x2d8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_etc_messip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b8,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6f(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe6d(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1298 <read_etc_messip+0x128>
mov    %rax,%r13
movl   $0xffffffff,(%r14)
test   %r12,%r12
je     11c9 <read_etc_messip+0x59>
movl   $0xffffffff,(%r12)
ff
lea    0xb0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12cc <read_etc_messip+0x15c>
xor    %ebp,%ebp
jmp    1209 <read_etc_messip+0x99>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12ba <read_etc_messip+0x14a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     1225 <read_etc_messip+0xb5>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1225 <read_etc_messip+0xb5>
movb   $0x0,0xaf(%rsp,%rax,1)
movzbl 0xb0(%rsp),%eax
cmp    $0x23,%al
je     11f0 <read_etc_messip+0x80>
test   %al,%al
je     11f0 <read_etc_messip+0x80>
mov    %rbx,%rdi
lea    0xe08(%rip),%rsi
lea    0x60(%rsp),%rbp
mov    %rbp,%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x10(%rsp),%r9
call   1080 <sscanf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
test   %r12,%r12
je     127a <read_etc_messip+0x10a>
mov    0x8(%rsp),%eax
mov    %eax,(%r12)
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
mov    $0x1,%bpl
test   %rax,%rax
jne    1209 <read_etc_messip+0x99>
jmp    12c0 <read_etc_messip+0x150>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%edx
lea    0xd6b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12e3 <read_etc_messip+0x173>
test   $0x1,%bpl
je     12cc <read_etc_messip+0x15c>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12e8 <read_etc_messip+0x178>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x2b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [16 x i8] c"/usr/etc/messip\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [43 x i8] c"Unable to open /usr/etc/messip - errno=%d\0A\00"
@errno = global i32 0
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [12 x i8] c"%s %d %d %s\00"
@.str.6 = [32 x i8] c"No hostname in /usr/etc/messip\0A\00"
define i32 @read_etc_messip(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [512 x i8]
%9 = alloca [80 x i8]
%10 = alloca [80 x i8]
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 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* %18, i32** %14
%19 = load i32*, i32** %14
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 -1, i32* %4
br label %87
25: ; preds = %3
%26 = load i32*, i32** %6
store i32 -1, i32* %26
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32*, i32** %7
store i32 -1, i32* %30
br label %31
31: ; preds = %29, %25
store i32 1, i32* %15
br label %32
32: ; preds = %77, %61, %31
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%34 = load i32*, i32** %14
%35 = call i64 @fgets(i8* %33, i32 511, i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %78
37: ; preds = %32
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
store i64 %39, i64* %11
%40 = icmp uge i64 %39, 1
br i1 %40, label %41, label %52
41: ; preds = %37
%42 = load i64, i64* %11
%43 = sub i64 %42, 1
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = load i64, i64* %11
%50 = sub i64 %49, 1
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %48, %41, %37
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%54 = call i32 @strcmp(i8* %53, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 35
br i1 %60, label %61, label %62
61: ; preds = %56, %52
br label %32
62: ; preds = %56
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%66 = call i32 @sscanf(i8* %63, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %64, i32* %12, i32* %13, i8* %65)
%67 = load i8*, i8** %5
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%69 = call i32 @strcpy(i8* %67, i8* %68)
%70 = load i32, i32* %12
%71 = load i32*, i32** %6
store i32 %70, i32* %71
%72 = load i32*, i32** %7
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %62
%75 = load i32, i32* %13
%76 = load i32*, i32** %7
store i32 %75, i32* %76
br label %77
77: ; preds = %74, %62
store i32 0, i32* %15
br label %32
78: ; preds = %32
%79 = load i32, i32* %15
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %87
84: ; preds = %78
%85 = load i32*, i32** %14
%86 = call i32 @fclose(i32* %85)
store i32 0, i32* %4
br label %87
87: ; preds = %84, %81, %21
%88 = load i32, i32* %4
ret i32 %88
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [16 x i8] c"/usr/etc/messip\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [43 x i8] c"Unable to open /usr/etc/messip - errno=%d\0A\00"
@errno = global i32 0
@.str.5 = [12 x i8] c"%s %d %d %s\00"
@.str.6 = [32 x i8] c"No hostname in /usr/etc/messip\0A\00"
define i32 @read_etc_messip(i8* %0, i32* nocapture writeonly %1, i32* writeonly %2) {
%4 = alloca [512 x i8]
%5 = alloca [80 x i8]
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %58
21: ; preds = %3
store i32 -1, i32* %1
%22 = icmp eq i32* %2, null
br i1 %22, label %24, label %23
23: ; preds = %21
store i32 -1, i32* %2
br label %24
24: ; preds = %23, %21
%25 = call i64 @fgets(i8* %9, i32 511, i32* %15)
%26 = icmp eq i64 %25, 0
br i1 %26, label %53, label %27
27: ; preds = %24, %49
%28 = phi i1 [ true, %49 ], [ false, %24 ]
br label %29
29: ; preds = %27, %40
%30 = call i64 @strlen(i8* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = add i64 %30, -1
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 10
br i1 %36, label %37, label %38
37: ; preds = %32
store i8 0, i8* %34
br label %38
38: ; preds = %37, %32, %29
%39 = load i8, i8* %9
switch i8 %39, label %43 [
i8 35, label %40
i8 0, label %40
]
40: ; preds = %38, %38
%41 = call i64 @fgets(i8* %9, i32 511, i32* %15)
%42 = icmp eq i64 %41, 0
br i1 %42, label %52, label %29
43: ; preds = %38
%44 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32* %7, i32* %8, i8* %11)
%45 = call i32 @strcpy(i8* %0, i8* %10)
%46 = load i32, i32* %7
store i32 %46, i32* %1
br i1 %22, label %49, label %47
47: ; preds = %43
%48 = load i32, i32* %8
store i32 %48, i32* %2
br label %49
49: ; preds = %47, %43
%50 = call i64 @fgets(i8* %9, i32 511, i32* %15)
%51 = icmp eq i64 %50, 0
br i1 %51, label %56, label %27
52: ; preds = %40
br i1 %28, label %56, label %53
53: ; preds = %24, %52
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %58
56: ; preds = %49, %52
%57 = call i32 @fclose(i32* %15)
br label %58
58: ; preds = %53, %56, %17
%59 = phi i32 [ -1, %17 ], [ -1, %53 ], [ 0, %56 ]
ret i32 %59
}