#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;
};
typedef int /*<<< orphan*/ raddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
scalar_t__ connect(int, void *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, long long *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long long);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int sd;
  FILE *fp;
  struct sockaddr_in raddr;
  long long stamp;
  if (argc < 2) {
    fprintf(stderr, "Usage...\n");
    exit(1);
  }
  sd = socket(AF_INET, SOCK_STREAM, 0);
  if (sd < 0) {
    perror("socket()");
    exit(1);
  }
  raddr.sin_family = AF_INET;
  raddr.sin_port = htons(atoi("1989"));
  inet_pton(AF_INET, argv[1], &raddr.sin_addr);
  if (connect(sd, (void *)&raddr, sizeof(raddr)) < 0) {
    perror("connect()");
    exit(1);
  }
  fp = fdopen(sd, "r+");
  if (fp == NULL) {
    perror("fdopen()");
    exit(1);
  }
  if (fscanf(fp, "%lld", &stamp) < 1)
    fprintf(stderr, "fscanf() error\n");
  else
    printf("stamp = %lld\n", stamp);
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ff <main+0x3f>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123b <main+0x7b>
lea    0xdde(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xdc5(%rip),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12a8 <main+0xe8>
lea    0xd7f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    0xd70(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12dc <main+0x11c>
lea    0xd58(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xd47(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jge    1313 <main+0x153>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1323 <main+0x163>
mov    -0x38(%rbp),%rsi
lea    0xd25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jg     11dd <main+0x2d>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rsi,%r14
mov    0x2e01(%rip),%r15
mov    (%r15),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    1207 <main+0x57>
lea    0xe05(%rip),%rdi
jmp    1269 <main+0xb9>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x7c5,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%edi
mov    0x8(%r14),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1080 <inet_pton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
jns    124f <main+0x9f>
lea    0xdc6(%rip),%rdi
jmp    1269 <main+0xb9>
lea    0xdc7(%rip),%rsi
mov    %ebx,%edi
call   1090 <fdopen@plt>
test   %rax,%rax
jne    1278 <main+0xc8>
lea    0xdb7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%rbx
lea    0xda7(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
test   %eax,%eax
jg     12aa <main+0xfa>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12bb <main+0x10b>
mov    0x8(%rsp),%rsi
lea    0xd88(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [10 x i8] c"Usage...\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [5 x i8] c"1989\00"
@.str.3 = [10 x i8] c"connect()\00"
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [9 x i8] c"fdopen()\00"
@.str.6 = [5 x i8] c"%lld\00"
@.str.7 = [16 x i8] c"fscanf() error\0A\00"
@.str.8 = [14 x i8] c"stamp = %lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.sockaddr_in
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @atoi(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @AF_INET
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%36 = call i32 @inet_pton(i32 %31, i8* %34, i32* %35)
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_in* %8 to i8*
%39 = call i64 @connect(i32 %37, i8* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %25
%42 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %25
%45 = load i32, i32* %6
%46 = call i32* @fdopen(i32 %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %7
%47 = load i32*, i32** %7
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %44
%53 = load i32*, i32** %7
%54 = call i32 @fscanf(i32* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i64* %9)
%55 = icmp slt i32 %54, 1
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %62
59: ; preds = %52
%60 = load i64, i64* %9
%61 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 %60)
br label %62
62: ; preds = %59, %56
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [10 x i8] c"Usage...\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.3 = [10 x i8] c"connect()\00"
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [9 x i8] c"fdopen()\00"
@.str.6 = [5 x i8] c"%lld\00"
@.str.7 = [16 x i8] c"fscanf() error\0A\00"
@.str.8 = [14 x i8] c"stamp = %lld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i64
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 1989)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%29 = call i32 @inet_pton(i32 %25, i8* %27, i32* %28)
%30 = call i64 @connect(i32 %15, i8* %5, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %20
%36 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35
%42 = call i32 @fscanf(i32* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i64* %4)
%43 = icmp slt i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %50
47: ; preds = %41
%48 = load i64, i64* %4
%49 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 %48)
br label %50
50: ; preds = %47, %44
%51 = call i32 @fclose(i32* %36)
%52 = call i32 @exit(i32 0)
unreachable
}