#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*/ uid_t;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int TcpCheckTcpLine(int, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ xFclose(int /*<<< orphan*/ *);
int TcpCheckIfClientIsMSS(int localPort, uid_t *uid) {
  FILE *fh;
  if ((fh = fopen("/proc/net/tcp", "r")) == NULL)
    perror("Unable to open proc/tcp");
  else {
    char line[1024];
    int nbLines = 0;
    while (fgets(line, sizeof(line), fh) != NULL) {
      if (TcpCheckTcpLine(nbLines, line, localPort, uid) == 1)
        return 1;
      nbLines++;
    }
    xFclose(fh);
  }
  return 0;
}


x86 assembly (clang, -O0):
<TcpCheckIfClientIsMSS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1194 <TcpCheckIfClientIsMSS+0x44>
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
jmp    1208 <TcpCheckIfClientIsMSS+0xb8>
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ff <TcpCheckIfClientIsMSS+0xaf>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1070 <TcpCheckTcpLine@plt>
cmp    $0x1,%eax
jne    11eb <TcpCheckIfClientIsMSS+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    120f <TcpCheckIfClientIsMSS+0xbf>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    119e <TcpCheckIfClientIsMSS+0x4e>
mov    -0x18(%rbp),%rdi
call   1030 <xFclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TcpCheckIfClientIsMSS>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xe94(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ee <TcpCheckIfClientIsMSS+0x9e>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11cd <TcpCheckIfClientIsMSS+0x7d>
xor    %ebp,%ebp
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1070 <TcpCheckTcpLine@plt>
cmp    $0x1,%eax
je     11d9 <TcpCheckIfClientIsMSS+0x89>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11a0 <TcpCheckIfClientIsMSS+0x50>
mov    %r12,%rdi
call   1030 <xFclose@plt>
xor    %eax,%eax
jmp    11de <TcpCheckIfClientIsMSS+0x8e>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1b(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    11de <TcpCheckIfClientIsMSS+0x8e>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/net/tcp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Unable to open proc/tcp\00"
define i32 @TcpCheckIfClientIsMSS(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %33
13: ; preds = %2
store i32 0, i32* %8
br label %14
14: ; preds = %27, %13
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %15, i32 1024, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32, i32* %8
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* %4
%23 = load i32*, i32** %5
%24 = call i32 @TcpCheckTcpLine(i32 %20, i8* %21, i32 %22, i32* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %3
br label %34
27: ; preds = %19
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %14
30: ; preds = %14
%31 = load i32*, i32** %6
%32 = call i32 @xFclose(i32* %31)
br label %33
33: ; preds = %30, %11
store i32 0, i32* %3
br label %34
34: ; preds = %33, %26
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/net/tcp\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Unable to open proc/tcp\00"
define i32 @TcpCheckIfClientIsMSS(i32 %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %23
8: ; preds = %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32* @fgets(i8* %9, i32 1024, i32* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %20, label %16
12: ; preds = %16
%13 = add nuw nsw i32 %17, 1
%14 = call i32* @fgets(i8* %9, i32 1024, i32* %4)
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %8, %12
%17 = phi i32 [ %13, %12 ], [ 0, %8 ]
%18 = call i32 @TcpCheckTcpLine(i32 %17, i8* %9, i32 %0, i32* %1)
%19 = icmp eq i32 %18, 1
br i1 %19, label %22, label %12
20: ; preds = %12, %8
%21 = call i32 @xFclose(i32* %4)
br label %23
22: ; preds = %16
br label %23
23: ; preds = %6, %20, %22
%24 = phi i32 [ 1, %22 ], [ 0, %20 ], [ 0, %6 ]
ret i32 %24
}