#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*/ rbuffer;

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int read_from_server(int conn) {
  char rbuffer[1024];
  int n;
  long ret;
  n = read(conn, rbuffer, sizeof(rbuffer));
  if (n < 0) {
    perror("ERROR reading from socket");
    return 0;
  }
  if (strncmp("HTTP/1.", rbuffer, 7)) {
    perror("ERROR not a HTTP response");
    return 0;
  }
  ret = atol(rbuffer + 9);
  return ret;
}


x86 assembly (clang, -O0):
<read_from_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    118d <read_from_server+0x4d>
lea    0xe84(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <read_from_server+0xa8>
lea    -0x410(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11c7 <read_from_server+0x87>
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <read_from_server+0xa8>
lea    -0x410(%rbp),%rdi
add    $0x9,%rdi
call   1050 <atol@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_server>:
sub    $0x408,%rsp
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
js     1183 <read_from_server+0x43>
lea    0xebb(%rip),%rdi
mov    %rsp,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    118c <read_from_server+0x4c>
lea    0x9(%rsp),%rdi
call   1050 <atol@plt>
add    $0x408,%rsp
ret
lea    0xe76(%rip),%rdi
jmp    1193 <read_from_server+0x53>
lea    0xe8f(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
add    $0x408,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [8 x i8] c"HTTP/1.\00"
@.str.2 = [26 x i8] c"ERROR not a HTTP response\00"
define i32 @read_from_server(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 1024)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %26
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 7)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %26
20: ; preds = %14
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 9
%23 = call i64 @atol(i8* %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = trunc i64 %24 to i32
store i32 %25, i32* %2
br label %26
26: ; preds = %20, %18, %12
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [8 x i8] c"HTTP/1.\00"
@.str.2 = [26 x i8] c"ERROR not a HTTP response\00"
define i32 @read_from_server(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1024)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
8: ; preds = %1
%9 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %17
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 9
%15 = call i64 @atol(i8* %14)
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %13, %11, %6
%18 = phi i32 [ 0, %6 ], [ 0, %11 ], [ %16, %13 ]
ret i32 %18
}