#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 size_t ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
size_t read(int, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int weather_filter_weather(int fd, unsigned char *weatherinfo) {
  char buf[256];
  char *p;
  ssize_t n;
  n = read(fd, buf, sizeof(buf) - 1);
  if (n < 0) {
    return -1;
  }
  buf[n] = '\0';
  p = strchr(buf, '<');
  *p = '\0';
  p = strstr(buf, ":");
  strncpy((char *)weatherinfo, p + 1, 255);
  return 0;
}


x86 assembly (clang, -O0):
<weather_filter_weather>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jae    1187 <weather_filter_weather+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <weather_filter_weather+0xb2>
mov    -0x120(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x118(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x118(%rbp),%rsi
add    $0x1,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weather_filter_weather>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
define i32 @weather_filter_weather(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
%9 = load i32, i32* %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = call i64 @read(i32 %9, i8* %10, i32 255)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = icmp ult i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %27
15: ; preds = %2
%16 = load i64, i64* %8
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i8* @strchr(i8* %18, i8 signext 60)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
store i8 0, i8* %20
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i8* @strstr(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %7
%23 = load i8*, i8** %5
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @strncpy(i8* %23, i8* %25, i32 255)
store i32 0, i32* %3
br label %27
27: ; preds = %15, %14
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @weather_filter_weather(i32 %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i64 @read(i32 %0, i8* %4, i32 255)
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %5
store i8 0, i8* %6
%7 = call i8* @strchr(i8* %4, i8 signext 60)
store i8 0, i8* %7
%8 = call i8* bitcast (i8* (i8*, i8)* @strchr to i8* (i8*, i32)*)(i8* %4, i32 58)
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = call i32 @strncpy(i8* %1, i8* %9, i32 255)
ret i32 0
}