#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  int /*<<< orphan*/ ai_socktype;
};
typedef int /*<<< orphan*/ hint;

/* Variables and functions */
int /*<<< orphan*/ SOCK_STREAM;
int connect_retry(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ err_exit(int, char *, char *);
int /*<<< orphan*/ err_quit(char *, ...);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_uptime(int);
int main(int argc, char *argv[]) {
  struct addrinfo *ailist, *aip;
  struct addrinfo hint;
  int sockfd, err;
  if (argc != 2)
    err_quit("usage: ruptime hostname");
  memset(&hint, 0, sizeof(hint));
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_canonname = NULL;
  hint.ai_addr = NULL;
  hint.ai_next = NULL;
  if ((err = getaddrinfo(argv[1], "ruptime", &hint, &ailist)) != 0)
    err_quit("getaddrinfo error: %s", gai_strerror(err));
  for (aip = ailist; aip != NULL; aip = aip->ai_next) {
    if ((sockfd = connect_retry(aip->ai_family, SOCK_STREAM, 0, aip->ai_addr,
                                aip->ai_addrlen)) < 0) {
      err = errno;
    } else {
      print_uptime(sockfd);
      exit(0);
    }
  }
  err_exit(err, "can't connect to %s", argv[1]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ae <main+0x2e>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <err_quit@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
je     1222 <main+0xa2>
mov    -0x58(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %eax,%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1060 <err_quit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     129d <main+0x11d>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8d
xor    %edx,%edx
call   1080 <connect_retry@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jge    1278 <main+0xf8>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
jmp    1287 <main+0x107>
mov    -0x54(%rbp),%edi
call   1030 <print_uptime@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    128c <main+0x10c>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    122a <main+0xaa>
mov    -0x58(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd87(%rip),%rsi
call   1070 <err_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     11a0 <main+0x20>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1060 <err_quit@plt>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    0x2e25(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x30(%rsp)
movq   $0x0,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
mov    0x8(%r14),%rdi
lea    0xe3b(%rip),%rsi
mov    %rsp,%rcx
mov    %rbp,%rdx
call   10a0 <getaddrinfo@plt>
mov    %eax,%r15d
test   %eax,%eax
je     1207 <main+0x87>
mov    %r15d,%edi
call   1040 <gai_strerror@plt>
lea    0xe22(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <err_quit@plt>
mov    (%rsp),%rbp
test   %rbp,%rbp
je     123b <main+0xbb>
mov    0x10(%rbp),%edi
mov    (%rbx),%esi
mov    0x8(%rbp),%rcx
mov    0x0(%rbp),%r8d
xor    %edx,%edx
call   1080 <connect_retry@plt>
test   %eax,%eax
jns    125b <main+0xdb>
mov    0x18(%rbp),%rbp
test   %rbp,%rbp
jne    1210 <main+0x90>
mov    0x2da0(%rip),%rax
mov    (%rax),%r15d
mov    0x8(%r14),%rdx
lea    0xdf0(%rip),%rsi
mov    %r15d,%edi
call   1070 <err_exit@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1030 <print_uptime@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32*, i32, %struct.addrinfo*, i32*, i32 }
@.str = [24 x i8] c"usage: ruptime hostname\00"
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"ruptime\00"
@.str.2 = [22 x i8] c"getaddrinfo error: %s\00"
@errno = global i32 0
@.str.3 = [20 x i8] c"can't connect to %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @err_quit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 48)
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32* null, i32** %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 1
store i32* null, i32** %20
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store %struct.addrinfo* null, %struct.addrinfo** %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @getaddrinfo(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %6)
store i32 %25, i32* %10
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = load i32, i32* %10
%29 = call i32 @gai_strerror(i32 %28)
%30 = call i32 (i8*, ...) @err_quit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %15
%32 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %32, %struct.addrinfo** %7
br label %33
33: ; preds = %56, %31
%34 = load %struct.addrinfo*, %struct.addrinfo** %7
%35 = icmp ne %struct.addrinfo* %34, null
br i1 %35, label %36, label %60
36: ; preds = %33
%37 = load %struct.addrinfo*, %struct.addrinfo** %7
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 2
%39 = load i32, i32* %38
%40 = load i32, i32* @SOCK_STREAM
%41 = load %struct.addrinfo*, %struct.addrinfo** %7
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 1
%43 = load i32*, i32** %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %7
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @connect_retry(i32 %39, i32 %40, i32 0, i32* %43, i32 %46)
store i32 %47, i32* %9
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %36
%50 = load i32, i32* @errno
store i32 %50, i32* %10
br label %55
51: ; preds = %36
%52 = load i32, i32* %9
%53 = call i32 @print_uptime(i32 %52)
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %49
br label %56
56: ; preds = %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %7
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 3
%59 = load %struct.addrinfo*, %struct.addrinfo** %58
store %struct.addrinfo* %59, %struct.addrinfo** %7
br label %33
60: ; preds = %33
%61 = load i32, i32* %10
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i8*, i8** %63
%65 = call i32 @err_exit(i32 %61, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32*, i32, %struct.addrinfo*, i32*, i32 }
@.str = [24 x i8] c"usage: ruptime hostname\00"
@SOCK_STREAM = global i32 0
@.str.1 = [8 x i8] c"ruptime\00"
@.str.2 = [22 x i8] c"getaddrinfo error: %s\00"
@errno = global i32 0
@.str.3 = [20 x i8] c"can't connect to %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = bitcast %struct.addrinfo** %3 to i8*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @err_quit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 48)
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
store i32* null, i32** %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = bitcast %struct.addrinfo** %15 to i8*
%18 = load i8*, i8** %16
%19 = call i32 @getaddrinfo(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %10
%22 = call i32 @gai_strerror(i32 %19)
%23 = call i32 (i8*, ...) @err_quit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %10
%25 = load %struct.addrinfo*, %struct.addrinfo** %3
%26 = icmp eq %struct.addrinfo* %25, null
br i1 %26, label %47, label %27
27: ; preds = %24, %38
%28 = phi %struct.addrinfo* [ %40, %38 ], [ %25, %24 ]
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 2
%30 = load i32, i32* %29
%31 = load i32, i32* @SOCK_STREAM
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 1
%33 = load i32*, i32** %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @connect_retry(i32 %30, i32 %31, i32 0, i32* %33, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %27
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 3
%40 = load %struct.addrinfo*, %struct.addrinfo** %39
%41 = icmp eq %struct.addrinfo* %40, null
br i1 %41, label %45, label %27
42: ; preds = %27
%43 = call i32 @print_uptime(i32 %36)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %38
%46 = load i32, i32* @errno
br label %47
47: ; preds = %45, %24
%48 = phi i32 [ %19, %24 ], [ %46, %45 ]
%49 = load i8*, i8** %16
%50 = call i32 @err_exit(i32 %48, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %49)
ret i32 0
}