#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read_stream(int, char *, int);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write_valid_weather_file(char *);
int get_predict() {
  int fd, len, flag;
  FILE *lfd;
  int lastpos;
  struct sockaddr_in i_a, my_addr;
  int pos = -1;
  char tmpfile[40];
  char reply[401];
  int havefeedback;
  int n;
  static char request[] = "GET /cgi-bin/cgi200010/query?03 \r\n\r\n";
  if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("socket create error");
    return -1;
  }
  memset(&i_a, 0, sizeof(struct sockaddr_in));
  i_a.sin_family = AF_INET;
  i_a.sin_addr.s_addr = inet_addr("202.106.103.7");
  i_a.sin_port = htons(80);
  if ((connect(fd, (struct sockaddr *)&i_a, sizeof(struct sockaddr))) == -1) {
    printf("connect error\n");
    return -2;
  }
  if (send(fd, request, strlen(request), 0) == -1) {
    printf("send error");
    return -3;
  }
  strcpy(tmpfile, "/home/bbs/tmp/");
  strcat(tmpfile, "predict.tmp");
  if ((lfd = fopen(tmpfile, "w")) == NULL) {
    printf("create tmp file error\n");
    printf("%s\n", tmpfile);
    return -4;
  }
  while ((n = read_stream(fd, reply, 400)) > 0) {
    fwrite(reply, n, 1, lfd);
  }
  close(fd);
  fclose(lfd);
  write_valid_weather_file(tmpfile);
  if (n < 0)
    printf("read error\n");
  unlink(tmpfile);
  exit(0);
}


x86 assembly (clang, -O0):
<get_predict>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0xffffffff,-0x3c(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1271 <get_predict+0x51>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1422 <get_predict+0x202>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xd80(%rip),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x50,%edi
call   1080 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    12dd <get_predict+0xbd>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1422 <get_predict+0x202>
mov    -0x8(%rbp),%eax
mov    %eax,-0x21c(%rbp)
lea    0x2dd3(%rip),%rdi
call   1070 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    %eax,%edx
lea    0x2dbf(%rip),%rsi
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
jne    132b <get_predict+0x10b>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1422 <get_predict+0x202>
lea    -0x70(%rbp),%rdi
lea    0xd06(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xd05(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xd01(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1395 <get_predict+0x175>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1422 <get_predict+0x202>
jmp    139a <get_predict+0x17a>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x190,%edx
call   10e0 <read_stream@plt>
mov    %eax,-0x218(%rbp)
cmp    $0x0,%eax
jle    13dd <get_predict+0x1bd>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1130 <fwrite@plt>
jmp    139a <get_predict+0x17a>
mov    -0x8(%rbp),%edi
call   10c0 <close@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    -0x70(%rbp),%rdi
call   1050 <write_valid_weather_file@plt>
cmpl   $0x0,-0x218(%rbp)
jge    1412 <get_predict+0x1f2>
lea    0xc69(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_predict>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1d8,%rsp
mov    0x2da4(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     1325 <get_predict+0xf5>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10c0 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0xd93(%rip),%rdi
call   10e0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x50,%edi
call   1090 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
je     133a <get_predict+0x10a>
lea    0x2e0a(%rip),%rbp
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
cmp    $0xffffffff,%eax
je     134d <get_predict+0x11d>
lea    0xd55(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
lea    0xd50(%rip),%rsi
mov    %rbp,%rdi
call   1110 <strcat@plt>
lea    0xd4d(%rip),%rsi
mov    %rbp,%rdi
call   1100 <fopen@plt>
test   %rax,%rax
jne    136e <get_predict+0x13e>
lea    0xd46(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rdi
call   1050 <puts@plt>
mov    $0xfffffffc,%eax
jmp    1360 <get_predict+0x130>
lea    0xcd4(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0xffffffff,%eax
jmp    1360 <get_predict+0x130>
lea    0xd2a(%rip),%rdi
call   1050 <puts@plt>
mov    $0xfffffffe,%eax
jmp    1360 <get_predict+0x130>
lea    0xcce(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0xfffffffd,%eax
add    $0x1d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%r14
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
mov    $0x190,%edx
call   10f0 <read_stream@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    13b4 <get_predict+0x184>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1140 <fwrite@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x190,%edx
call   10f0 <read_stream@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     138d <get_predict+0x15d>
mov    %ebx,%edi
call   10d0 <close@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
lea    0x10(%rsp),%rdi
call   1060 <write_valid_weather_file@plt>
test   %ebp,%ebp
jns    13dd <get_predict+0x1ad>
lea    0xc72(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@get_predict.request = internal global [37 x i8] c"GET /cgi-bin/cgi200010/query?03 \0D\0A\0D\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"socket create error\00"
@.str.1 = [14 x i8] c"202.106.103.7\00"
@.str.2 = [15 x i8] c"connect error\0A\00"
@.str.3 = [11 x i8] c"send error\00"
@.str.4 = [15 x i8] c"/home/bbs/tmp/\00"
@.str.5 = [12 x i8] c"predict.tmp\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [23 x i8] c"create tmp file error\0A\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [12 x i8] c"read error\0A\00"
define i32 @get_predict() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [40 x i8]
%11 = alloca [401 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 -1, i32* %9
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %80
20: ; preds = %0
%21 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 80)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 4)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %1
br label %80
35: ; preds = %20
%36 = load i32, i32* %2
%37 = call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @get_predict.request, i64 0, i64 0))
%38 = call i32 @send(i32 %36, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @get_predict.request, i64 0, i64 0), i32 %37, i32 0)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 -3, i32* %1
br label %80
42: ; preds = %35
%43 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%45 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%47 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %48, i32** %5
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %54
50: ; preds = %42
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%52 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %52)
store i32 -4, i32* %1
br label %80
54: ; preds = %42
br label %55
55: ; preds = %60, %54
%56 = load i32, i32* %2
%57 = getelementptr inbounds [401 x i8], [401 x i8]* %11, i64 0, i64 0
%58 = call i32 @read_stream(i32 %56, i8* %57, i32 400)
store i32 %58, i32* %13
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = getelementptr inbounds [401 x i8], [401 x i8]* %11, i64 0, i64 0
%62 = load i32, i32* %13
%63 = load i32*, i32** %5
%64 = call i32 @fwrite(i8* %61, i32 %62, i32 1, i32* %63)
br label %55
65: ; preds = %55
%66 = load i32, i32* %2
%67 = call i32 @close(i32 %66)
%68 = load i32*, i32** %5
%69 = call i32 @fclose(i32* %68)
%70 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%71 = call i32 @write_valid_weather_file(i8* %70)
%72 = load i32, i32* %13
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %65
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %76
76: ; preds = %74, %65
%77 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%78 = call i32 @unlink(i8* %77)
%79 = call i32 @exit(i32 0)
unreachable
80: ; preds = %50, %40, %33, %18
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@get_predict.request = internal global [37 x i8] c"GET /cgi-bin/cgi200010/query?03 \0D\0A\0D\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"socket create error\00"
@.str.1 = [14 x i8] c"202.106.103.7\00"
@.str.3 = [11 x i8] c"send error\00"
@.str.4 = [15 x i8] c"/home/bbs/tmp/\00"
@.str.5 = [12 x i8] c"predict.tmp\00"
@.str.6 = [2 x i8] c"w\00"
@str = [11 x i8] c"read error\00"
@str.10 = [22 x i8] c"create tmp file error\00"
@str.11 = [14 x i8] c"connect error\00"
define i32 @get_predict() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [40 x i8]
%3 = alloca [401 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [401 x i8], [401 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %59
13: ; preds = %0
%14 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = call i32 @htons(i32 80)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @connect(i32 %9, %struct.sockaddr* %21, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
br label %59
26: ; preds = %13
%27 = call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @get_predict.request, i64 0, i64 0))
%28 = call i32 @send(i32 %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @get_predict.request, i64 0, i64 0), i32 %27, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %59
32: ; preds = %26
%33 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = call i32 @read_stream(i32 %9, i8* %6, i32 400)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %43, label %48
40: ; preds = %32
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%42 = call i32 @puts(i8* %5)
br label %59
43: ; preds = %37, %43
%44 = phi i32 [ %46, %43 ], [ %38, %37 ]
%45 = call i32 @fwrite(i8* %6, i32 %44, i32 1, i32* %35)
%46 = call i32 @read_stream(i32 %9, i8* %6, i32 400)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %43, label %48
48: ; preds = %43, %37
%49 = phi i32 [ %38, %37 ], [ %46, %43 ]
%50 = call i32 @close(i32 %9)
%51 = call i32 @fclose(i32* %35)
%52 = call i32 @write_valid_weather_file(i8* %5)
%53 = icmp slt i32 %49, 0
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = call i32 @unlink(i8* %5)
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %40, %30, %24, %11
%60 = phi i32 [ -1, %11 ], [ -2, %24 ], [ -3, %30 ], [ -4, %40 ]
ret i32 %60
}