#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int getTemp() {
  int sockfd, n;
  int temp = 9999;
  char recvLine[4096 + 1];
  char sndline[4096 + 1];
  char *firstTag = NULL;
  struct sockaddr_in servaddr;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    fprintf(stderr, "socket error :( \n");
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(80);
  if (inet_pton(AF_INET, "187.45.240.36", &servaddr.sin_addr) <= 0)
    fprintf(stderr, "inet_pton error for %s :(\n", "187.45.240.36");
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    fprintf(stderr, "connect error :(\n");
  strcpy(sndline, "GET /tempo/xml/saopaulo-sp HTTP/1.1\nhost: "
                  "www.developers.agenciaideias.com.br\n\n");
  if (write(sockfd, sndline, strlen(sndline)) < 0)
    fprintf(stderr, "write error :(\n");
  while ((n = read(sockfd, recvLine, 4096)) > 0) {
    recvLine[n] = '\0';
    if (temp == 9999) {
      firstTag = strstr(recvLine, "<temperatura>");
      if (firstTag == NULL)
        continue;
      sscanf(firstTag + 13, "%d", &temp);
    }
  }
  close(sockfd);
  return temp;
}


x86 assembly (clang, -O0):
<getTemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x270f,-0xc(%rbp)
movq   $0x0,-0x2028(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1229 <getTemp+0x59>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x2038(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2030(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x2034(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    -0x2038(%rbp),%rdx
lea    0xda2(%rip),%rsi
call   10a0 <inet_pton@plt>
cmp    $0x0,%rax
jg     129d <getTemp+0xcd>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
lea    0xd7c(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x2038(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12d2 <getTemp+0x102>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x2020(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2044(%rbp)
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2040(%rbp)
lea    -0x2020(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2044(%rbp),%edi
mov    -0x2040(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    133d <getTemp+0x16d>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1342 <getTemp+0x172>
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    13c8 <getTemp+0x1f8>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
cmpl   $0x270f,-0xc(%rbp)
jne    13c3 <getTemp+0x1f3>
lea    -0x1010(%rbp),%rdi
lea    0xd24(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x0,-0x2028(%rbp)
jne    13a8 <getTemp+0x1d8>
jmp    1342 <getTemp+0x172>
mov    -0x2028(%rbp),%rdi
add    $0xd,%rdi
lea    0xd01(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   10b0 <sscanf@plt>
jmp    1342 <getTemp+0x172>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTemp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2040,%rsp
movl   $0x270f,0xc(%rsp)
mov    0x2dfa(%rip),%r14
mov    (%r14),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    121e <getTemp+0x4e>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r14),%edi
lea    0xdc3(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <inet_pton@plt>
test   %rax,%rax
jg     127a <getTemp+0xaa>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
lea    0xd9f(%rip),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
jns    12a7 <getTemp+0xd7>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xd9f(%rip),%rsi
lea    0x1030(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12ee <getTemp+0x11e>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    136a <getTemp+0x19a>
mov    $0x270f,%ecx
lea    0xd9e(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xda0(%rip),%r15
lea    0xc(%rsp),%r12
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
cmp    $0x270f,%ecx
jne    1351 <getTemp+0x181>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1351 <getTemp+0x181>
add    $0xd,%rax
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <sscanf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    136a <getTemp+0x19a>
mov    0xc(%rsp),%ecx
jmp    1320 <getTemp+0x150>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0xc(%rsp),%eax
add    $0x2040,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"socket error :( \0A\00"
@.str.1 = [14 x i8] c"187.45.240.36\00"
@.str.2 = [27 x i8] c"inet_pton error for %s :(\0A\00"
@.str.3 = [18 x i8] c"connect error :(\0A\00"
@.str.4 = [80 x i8] c"GET /tempo/xml/saopaulo-sp HTTP/1.1\0Ahost: www.developers.agenciaideias.com.br\0A\0A\00"
@.str.5 = [16 x i8] c"write error :(\0A\00"
@.str.6 = [14 x i8] c"<temperatura>\00"
@.str.7 = [3 x i8] c"%d\00"
define i32 @getTemp() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4097 x i8]
%5 = alloca [4097 x i8]
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
store i32 9999, i32* %3
store i8* null, i8** %6
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %0
%16 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 80)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%23 = call i64 @inet_pton(i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %15
%29 = load i32, i32* %1
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i64 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33, %28
%37 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %1
%40 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%41 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = call i64 @write(i32 %39, i8* %40, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %45, %36
br label %49
49: ; preds = %70, %65, %48
%50 = load i32, i32* %1
%51 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%52 = call i32 @read(i32 %50, i8* %51, i32 4096)
store i32 %52, i32* %2
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %71
54: ; preds = %49
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %56
store i8 0, i8* %57
%58 = load i32, i32* %3
%59 = icmp eq i32 %58, 9999
br i1 %59, label %60, label %70
60: ; preds = %54
%61 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%62 = call i8* @strstr(i8* %61, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i8* %62, i8** %6
%63 = load i8*, i8** %6
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %66
65: ; preds = %60
br label %49
66: ; preds = %60
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 13
%69 = call i32 @sscanf(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %3)
br label %70
70: ; preds = %66, %54
br label %49
71: ; preds = %49
%72 = load i32, i32* %1
%73 = call i32 @close(i32 %72)
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"socket error :( \0A\00"
@.str.1 = [14 x i8] c"187.45.240.36\00"
@.str.2 = [27 x i8] c"inet_pton error for %s :(\0A\00"
@.str.3 = [18 x i8] c"connect error :(\0A\00"
@.str.4 = [80 x i8] c"GET /tempo/xml/saopaulo-sp HTTP/1.1\0Ahost: www.developers.agenciaideias.com.br\0A\0A\00"
@.str.5 = [16 x i8] c"write error :(\0A\00"
@.str.6 = [14 x i8] c"<temperatura>\00"
@.str.7 = [3 x i8] c"%d\00"
define i32 @getTemp() {
%1 = alloca i32
%2 = alloca [4097 x i8]
%3 = alloca [4097 x i8]
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %1 to i8*
store i32 9999, i32* %1
%6 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %0
%17 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 80)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%24 = call i64 @inet_pton(i32 %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = icmp slt i64 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %16
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%31 = call i64 @connect(i32 %11, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33, %29
%37 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @strlen(i8* %7)
%39 = call i64 @write(i32 %11, i8* %7, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
%45 = call i32 @read(i32 %11, i8* %6, i32 4096)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %44, %62
%48 = phi i32 [ %63, %62 ], [ 9999, %44 ]
%49 = phi i32 [ %60, %62 ], [ %45, %44 ]
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 %50
store i8 0, i8* %51
%52 = icmp eq i32 %48, 9999
br i1 %52, label %53, label %59
53: ; preds = %47
%54 = call i8* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp eq i8* %54, null
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = getelementptr inbounds i8, i8* %54, i64 13
%58 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
br label %59
59: ; preds = %47, %56, %53
%60 = call i32 @read(i32 %11, i8* %6, i32 4096)
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = load i32, i32* %1
br label %47
64: ; preds = %59, %44
%65 = call i32 @close(i32 %11)
%66 = load i32, i32* %1
ret i32 %66
}