#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *, int *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int read_etc_messip(char *hostname, int *port_used, int *port_http_used) {
  FILE *fp;
  char line[512], host[80], path[80];
  int len, first;
  int port, port_http;
  strcpy(hostname, "localhost");
  fp = fopen("/etc/messip", "r");
  if (fp == NULL) {
    perror("open(\""
           "/etc/messip"
           "\")");
    return -1;
  }
  *port_used = -1;
  if (port_http_used != NULL)
    *port_http_used = -1;
  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;
  }
  fclose(fp);
  if (first) {
    fprintf(stderr, "No hostname in "
                    "/etc/messip"
                    "\n");
    return -1;
  }
  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    0xe4e(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe4c(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f1 <read_etc_messip+0x61>
lea    0xe38(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <read_etc_messip+0x1d3>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1210 <read_etc_messip+0x80>
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x1,-0x2d8(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x1ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1325 <read_etc_messip+0x195>
lea    -0x230(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2d4(%rbp)
cmp    $0x1,%eax
jl     1283 <read_etc_messip+0xf3>
mov    -0x2d4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x230(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1283 <read_etc_messip+0xf3>
mov    -0x2d4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x230(%rbp,%rax,1)
lea    -0x230(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12af <read_etc_messip+0x11f>
movsbl -0x230(%rbp),%eax
cmp    $0x23,%eax
jne    12b4 <read_etc_messip+0x124>
jmp    121a <read_etc_messip+0x8a>
lea    -0x230(%rbp),%rdi
lea    -0x280(%rbp),%rdx
lea    -0x2d0(%rbp),%r9
lea    0xd5c(%rip),%rsi
lea    -0x2dc(%rbp),%rcx
lea    -0x2e0(%rbp),%r8
call   1090 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x280(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x2dc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1316 <read_etc_messip+0x186>
mov    -0x2e0(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x2d8(%rbp)
jmp    121a <read_etc_messip+0x8a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x2d8(%rbp)
je     135c <read_etc_messip+0x1cc>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1363 <read_etc_messip+0x1d3>
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    0xe5f(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe5d(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     130d <read_etc_messip+0x18d>
mov    %rax,%r13
movl   $0xffffffff,(%r14)
test   %r12,%r12
je     11d9 <read_etc_messip+0x59>
movl   $0xffffffff,(%r12)
ff
lea    0xb0(%rsp),%rdi
mov    $0x1ff,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12d9 <read_etc_messip+0x159>
xor    %ebp,%ebp
lea    0xb0(%rsp),%rbx
jmp    1229 <read_etc_messip+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12c7 <read_etc_messip+0x147>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    124a <read_etc_messip+0xca>
add    $0xffffffff,%eax
cmpb   $0xa,0xb0(%rsp,%rax,1)
0a
jne    124a <read_etc_messip+0xca>
movb   $0x0,0xb0(%rsp,%rax,1)
movzbl 0xb0(%rsp),%eax
cmp    $0x23,%al
je     1210 <read_etc_messip+0x90>
test   %al,%al
je     1210 <read_etc_messip+0x90>
mov    %rbx,%rdi
lea    0xdc8(%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     129f <read_etc_messip+0x11f>
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    1229 <read_etc_messip+0xa9>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12fb <read_etc_messip+0x17b>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
test   $0x1,%bpl
je     12e1 <read_etc_messip+0x161>
jmp    12fb <read_etc_messip+0x17b>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x2b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd04(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f6 <read_etc_messip+0x176>

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

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