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

/* Variables and functions */
int /*<<< orphan*/ UI_err_exit(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getline(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int tcp_connect(char *, int);
int UI_check_for_updates(void) {
  int sd;
  char buf[512];
  if ((sd = tcp_connect("tmsnc.sourceforge.net", 80)) < 0)
    UI_err_exit("Couldn't connect to tmsnc.sf.net");
  if (send(sd,
           "GET /version.txt HTTP/1.1\r\n"
           "Host: tmsnc.sourceforge.net\r\n\r\n",
           59, 0) < 0)
    UI_err_exit("Couldn't send HTTP request");
  while (getline(buf, sizeof(buf) - 1, sd) > 0) {
    buf[strlen(buf) - 1] = 0x0;
    if (strncmp(buf, "Version", 7) == 0) {
      if (strcmp(&buf[9], "0.3.2") == 0) {
        printf("You have the newest version installed\n");
        exit(0);
      } else {
        printf("Newer version (%s) available at "
               "http://tmsnc.sf.net\n",
               &buf[9]);
        exit(0);
      }
    }
  }
  UI_err_exit("Unknown error");
  return 0;
}


x86 assembly (clang, -O0):
<UI_check_for_updates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
lea    0xe5e(%rip),%rdi
mov    $0x50,%esi
call   1040 <tcp_connect@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11c4 <UI_check_for_updates+0x34>
lea    0xe57(%rip),%rdi
call   10b0 <UI_err_exit@plt>
mov    -0x4(%rbp),%edi
lea    0xe69(%rip),%rsi
mov    $0x3b,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x0,%rax
jge    11f0 <UI_check_for_updates+0x60>
lea    0xe87(%rip),%rdi
call   10b0 <UI_err_exit@plt>
jmp    11f5 <UI_check_for_updates+0x65>
lea    -0x210(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0x1ff,%esi
call   1090 <getline@plt>
cmp    $0x0,%rax
jle    12a9 <UI_check_for_updates+0x119>
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a4 <UI_check_for_updates+0x114>
lea    -0x210(%rbp),%rdi
add    $0x9,%rdi
lea    0xe35(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1284 <UI_check_for_updates+0xf4>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rsi
add    $0x9,%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    11f5 <UI_check_for_updates+0x65>
lea    0xe47(%rip),%rdi
call   10b0 <UI_err_exit@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UI_check_for_updates>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
lea    0xe4e(%rip),%rdi
mov    $0x50,%esi
call   1050 <tcp_connect@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ce <UI_check_for_updates+0x2e>
lea    0xe4d(%rip),%rdi
call   10c0 <UI_err_exit@plt>
lea    0xe62(%rip),%rsi
mov    %ebp,%edi
mov    $0x3b,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    11f4 <UI_check_for_updates+0x54>
lea    0xe83(%rip),%rdi
call   10c0 <UI_err_exit@plt>
mov    %rsp,%rbx
lea    0xe8f(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %ebp,%edx
call   10a0 <getline@plt>
test   %rax,%rax
jle    1264 <UI_check_for_updates+0xc4>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1200 <UI_check_for_updates+0x60>
lea    0x9(%rsp),%rbx
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    127e <UI_check_for_updates+0xde>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xe65(%rip),%rdi
call   10c0 <UI_err_exit@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe16(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"tmsnc.sourceforge.net\00"
@.str.1 = [33 x i8] c"Couldn't connect to tmsnc.sf.net\00"
@.str.2 = [59 x i8] c"GET /version.txt HTTP/1.1\0D\0AHost: tmsnc.sourceforge.net\0D\0A\0D\0A\00"
@.str.3 = [27 x i8] c"Couldn't send HTTP request\00"
@.str.4 = [8 x i8] c"Version\00"
@.str.5 = [6 x i8] c"0.3.2\00"
@.str.6 = [39 x i8] c"You have the newest version installed\0A\00"
@.str.7 = [53 x i8] c"Newer version (%s) available at http://tmsnc.sf.net\0A\00"
@.str.8 = [14 x i8] c"Unknown error\00"
define i32 @UI_check_for_updates() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = call i32 @tcp_connect(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 80)
store i32 %3, i32* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @UI_err_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32, i32* %1
%9 = call i64 @send(i32 %8, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 59, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @UI_err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %39, %13
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* %1
%17 = call i64 @getline(i8* %15, i32 511, i32 %16)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %40
19: ; preds = %14
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %19
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 9
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %28
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %19
br label %14
40: ; preds = %14
%41 = call i32 @UI_err_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"tmsnc.sourceforge.net\00"
@.str.1 = [33 x i8] c"Couldn't connect to tmsnc.sf.net\00"
@.str.2 = [59 x i8] c"GET /version.txt HTTP/1.1\0D\0AHost: tmsnc.sourceforge.net\0D\0A\0D\0A\00"
@.str.3 = [27 x i8] c"Couldn't send HTTP request\00"
@.str.4 = [8 x i8] c"Version\00"
@.str.5 = [6 x i8] c"0.3.2\00"
@.str.7 = [53 x i8] c"Newer version (%s) available at http://tmsnc.sf.net\0A\00"
@.str.8 = [14 x i8] c"Unknown error\00"
@str = [38 x i8] c"You have the newest version installed\00"
define i32 @UI_check_for_updates() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @tcp_connect(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 80)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @UI_err_exit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i64 @send(i32 %3, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 59, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @UI_err_exit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
br label %13
13: ; preds = %12, %16
%14 = call i64 @getline(i8* %2, i32 511, i32 %3)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = call i32 @strlen(i8* %2)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %13
23: ; preds = %16
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 9
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8* %24)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %13
%34 = call i32 @UI_err_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}