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

/* Variables and functions */
int atoi(char *);
scalar_t__ get_server(char *);
int /*<<< orphan*/ myerror(char *);
scalar_t__ nntp_connect(char *, int, char *);
int /*<<< orphan*/ put_server(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int connect_server(char *host, int port) {
  char line1[512 + 2];
  char line2[512];
  if (nntp_connect(host, port, line1) < 0) {
    if (line1[0] == '\0') {
      myerror("I/O problem");
      return -1;
    }
    myerror("Server rejected connection; return it's reply code.");
    return atoi(line1);
  }
  put_server("MODE READER");
  if (get_server(line2) < 0)
    return -1;
  if (atoi(line2) != 500)
    strcpy(line1, line2);
  return atoi(line1);
}


x86 assembly (clang, -O0):
<connect_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x220(%rbp),%rdx
call   1060 <nntp_connect@plt>
cmp    $0x0,%rax
jge    11d7 <connect_server+0x77>
movsbl -0x220(%rbp),%eax
cmp    $0x0,%eax
jne    11b7 <connect_server+0x57>
lea    0xe5a(%rip),%rdi
call   1050 <myerror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123e <connect_server+0xde>
lea    0xe4e(%rip),%rdi
call   1050 <myerror@plt>
lea    -0x220(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    123e <connect_server+0xde>
lea    0xe62(%rip),%rdi
call   1070 <put_server@plt>
lea    -0x420(%rbp),%rdi
call   1040 <get_server@plt>
cmp    $0x0,%rax
jge    1205 <connect_server+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    123e <connect_server+0xde>
lea    -0x420(%rbp),%rdi
call   1080 <atoi@plt>
cmp    $0x1f4,%eax
je     122f <connect_server+0xcf>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_server>:
sub    $0x418,%rsp
mov    %rsp,%rdx
call   1060 <nntp_connect@plt>
test   %rax,%rax
js     11b8 <connect_server+0x58>
lea    0xec5(%rip),%rdi
call   1070 <put_server@plt>
lea    0x210(%rsp),%rdi
call   1040 <get_server@plt>
test   %rax,%rax
js     11e6 <connect_server+0x86>
lea    0x210(%rsp),%rdi
call   1080 <atoi@plt>
cmp    $0x1f4,%eax
je     11ca <connect_server+0x6a>
mov    %rsp,%rdi
lea    0x210(%rsp),%rsi
call   1030 <strcpy@plt>
jmp    11ca <connect_server+0x6a>
cmpb   $0x0,(%rsp)
je     11da <connect_server+0x7a>
lea    0xe47(%rip),%rdi
call   1050 <myerror@plt>
mov    %rsp,%rdi
call   1080 <atoi@plt>
add    $0x418,%rsp
ret
lea    0xe1f(%rip),%rdi
call   1050 <myerror@plt>
mov    $0xffffffff,%eax
add    $0x418,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"I/O problem\00"
@.str.1 = [52 x i8] c"Server rejected connection; return it's reply code.\00"
@.str.2 = [12 x i8] c"MODE READER\00"
define i32 @connect_server(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [514 x i8]
%7 = alloca [512 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = getelementptr inbounds [514 x i8], [514 x i8]* %6, i64 0, i64 0
%11 = call i64 @nntp_connect(i8* %8, i32 %9, i8* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = getelementptr inbounds [514 x i8], [514 x i8]* %6, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @myerror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
20: ; preds = %13
%21 = call i32 @myerror(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [514 x i8], [514 x i8]* %6, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %3
br label %41
24: ; preds = %2
%25 = call i32 @put_server(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%27 = call i64 @get_server(i8* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 -1, i32* %3
br label %41
30: ; preds = %24
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%32 = call i32 @atoi(i8* %31)
%33 = icmp ne i32 %32, 500
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = getelementptr inbounds [514 x i8], [514 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%37 = call i32 @strcpy(i8* %35, i8* %36)
br label %38
38: ; preds = %34, %30
%39 = getelementptr inbounds [514 x i8], [514 x i8]* %6, i64 0, i64 0
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %29, %20, %18
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [12 x i8] c"I/O problem\00"
@.str.1 = [52 x i8] c"Server rejected connection; return it's reply code.\00"
@.str.2 = [12 x i8] c"MODE READER\00"
define i32 @connect_server(i8* %0, i32 %1) {
%3 = alloca [514 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [514 x i8], [514 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = call i64 @nntp_connect(i8* %0, i32 %1, i8* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i8, i8* %5
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @myerror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %28
14: ; preds = %9
%15 = call i32 @myerror(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @atoi(i8* %5)
br label %28
17: ; preds = %2
%18 = call i32 @put_server(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%19 = call i64 @get_server(i8* %6)
%20 = icmp slt i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = call i32 @atoi(i8* %6)
%23 = icmp eq i32 %22, 500
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @strcpy(i8* %5, i8* %6)
br label %26
26: ; preds = %24, %21
%27 = call i32 @atoi(i8* %5)
br label %28
28: ; preds = %17, %26, %14, %12
%29 = phi i32 [ -1, %12 ], [ %16, %14 ], [ %27, %26 ], [ -1, %17 ]
ret i32 %29
}