#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fstat(int, struct stat *);
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcspn(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  int port;
  char ip[20];
  int thread_num;
  int confd;
  char *buf;
  char *index;
  char *temp;
  struct stat f_stat;
  confd = open(argv[1], O_RDONLY);
  if (confd <= -1) {
    perror("open");
    exit(1);
  }
  fstat(confd, &f_stat);
  buf =
      mmap(NULL, f_stat.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, confd, 0);
  if (*(int *)buf <= -1) {
    perror("write");
    exit(1);
  }
  if ((index = strstr(buf, "port:")) != NULL) {
    index += 5;
    port = atoi(index);
    printf("port number %d\n", port);
  };
  if ((index = strstr(buf, "threadnumber:")) != NULL) {
    index += 13;
    thread_num = atoi(index);
    printf("thread number %d\n", thread_num);
  }
  if ((index = strstr(buf, "address:")) != NULL) {
    index += 9;
    char *point = index;
    point += strcspn(index, " \r\n");
    *point = '\0';
    strncpy(ip, index, strlen(index) + 1);
    printf("ipaddress %s\n", ip);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jg     11ff <main+0x4f>
lea    0xe10(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x38(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10c0 <fstat@plt>
mov    -0x58(%rbp),%esi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    0x2db2(%rip),%rax
or     (%rax),%edx
mov    0x2da1(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jg     1260 <main+0xb0>
lea    0xdb4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     12a7 <main+0xf7>
mov    -0x48(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     12ee <main+0x13e>
mov    -0x48(%rbp),%rax
add    $0xd,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     1386 <main+0x1d6>
mov    -0x48(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     12e3 <main+0x133>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10c0 <fstat@plt>
mov    0x8(%rsp),%esi
mov    0x2e0e(%rip),%rax
mov    0x2ddf(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2dcc(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmpl   $0x0,(%rax)
js     12ec <main+0x13c>
mov    %rax,%rbx
lea    0xded(%rip),%rsi
mov    %rax,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1247 <main+0x97>
add    $0x5,%rax
mov    %rax,%rdi
call   10a0 <atoi@plt>
lea    0xdd3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd3(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1277 <main+0xc7>
add    $0xd,%rax
mov    %rax,%rdi
call   10a0 <atoi@plt>
lea    0xdc1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdc3(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     12d9 <main+0x129>
mov    %rax,%r14
mov    %rax,%rbx
add    $0x9,%rbx
lea    0xdae(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcspn@plt>
cltq
movb   $0x0,0x9(%r14,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0xd7f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd16(%rip),%rdi
jmp    12f3 <main+0x143>
lea    0xd12(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [6 x i8] c"port:\00"
@.str.3 = [16 x i8] c"port number %d\0A\00"
@.str.4 = [14 x i8] c"threadnumber:\00"
@.str.5 = [18 x i8] c"thread number %d\0A\00"
@.str.6 = [9 x i8] c"address:\00"
@.str.7 = [4 x i8] c" \0D\0A\00"
@.str.8 = [14 x i8] c"ipaddress %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca %struct.stat
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp sle i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32, i32* %9
%27 = call i32 @fstat(i32 %26, %struct.stat* %13)
%28 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @PROT_WRITE
%32 = or i32 %30, %31
%33 = load i32, i32* @MAP_PRIVATE
%34 = load i32, i32* %9
%35 = call i8* @mmap(i32* null, i32 %29, i32 %32, i32 %33, i32 %34, i32 0)
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = bitcast i8* %36 to i32*
%38 = load i32, i32* %37
%39 = icmp sle i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %25
%41 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %25
%44 = load i8*, i8** %10
%45 = call i8* @strstr(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %45, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %54
47: ; preds = %43
%48 = load i8*, i8** %11
%49 = getelementptr inbounds i8, i8* %48, i64 5
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %47, %43
%55 = load i8*, i8** %10
%56 = call i8* @strstr(i8* %55, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i8* %56, i8** %11
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %65
58: ; preds = %54
%59 = load i8*, i8** %11
%60 = getelementptr inbounds i8, i8* %59, i64 13
store i8* %60, i8** %11
%61 = load i8*, i8** %11
%62 = call i32 @atoi(i8* %61)
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %58, %54
%66 = load i8*, i8** %10
%67 = call i8* @strstr(i8* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i8* %67, i8** %11
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %87
69: ; preds = %65
%70 = load i8*, i8** %11
%71 = getelementptr inbounds i8, i8* %70, i64 9
store i8* %71, i8** %11
%72 = load i8*, i8** %11
store i8* %72, i8** %14
%73 = load i8*, i8** %11
%74 = call i32 @strcspn(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%75 = load i8*, i8** %14
%76 = sext i32 %74 to i64
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8* %77, i8** %14
%78 = load i8*, i8** %14
store i8 0, i8* %78
%79 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%80 = load i8*, i8** %11
%81 = load i8*, i8** %11
%82 = call i64 @strlen(i8* %81)
%83 = add nsw i64 %82, 1
%84 = call i32 @strncpy(i8* %79, i8* %80, i64 %83)
%85 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %69, %65
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [6 x i8] c"write\00"
@.str.2 = [6 x i8] c"port:\00"
@.str.3 = [16 x i8] c"port number %d\0A\00"
@.str.4 = [14 x i8] c"threadnumber:\00"
@.str.5 = [18 x i8] c"thread number %d\0A\00"
@.str.6 = [9 x i8] c"address:\00"
@.str.7 = [4 x i8] c" \0D\0A\00"
@.str.8 = [14 x i8] c"ipaddress %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 @fstat(i32 %10, %struct.stat* %4)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @PROT_READ
%20 = load i32, i32* @PROT_WRITE
%21 = or i32 %20, %19
%22 = load i32, i32* @MAP_PRIVATE
%23 = tail call i8* @mmap(i32* null, i32 %18, i32 %21, i32 %22, i32 %10, i32 0)
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %15
%31 = tail call i8* @strstr(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = getelementptr inbounds i8, i8* %31, i64 5
%35 = tail call i32 @atoi(i8* %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %33, %30
%38 = tail call i8* @strstr(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = getelementptr inbounds i8, i8* %38, i64 13
%42 = tail call i32 @atoi(i8* %41)
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %40, %37
%45 = tail call i8* @strstr(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp eq i8* %45, null
br i1 %46, label %56, label %47
47: ; preds = %44
%48 = getelementptr inbounds i8, i8* %45, i64 9
%49 = tail call i32 @strcspn(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = tail call i64 @strlen(i8* %48)
%53 = add nsw i64 %52, 1
%54 = call i32 @strncpy(i8* %5, i8* %48, i64 %53)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %5)
br label %56
56: ; preds = %47, %44
ret i32 0
}