#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int time_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_adr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ErrorHandling(char *);
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ time(int *);
int main(int argc, char *argv[]) {
  int sd;
  FILE *fp;
  char buf[1024];
  int read_cnt;
  struct sockaddr_in serv_adr;
  if (argc != 3) {
    printf("Usage: %s <IP> <port>\n", argv[0]);
    exit(1);
  }
  time_t current_time;
  time(&current_time);
  char file_name[1024];
  sprintf(file_name, "%d.pdf", current_time);
  printf("%s\n", file_name);
  fp = fopen(file_name, "wb");
  sd = socket(PF_INET, SOCK_STREAM, 0);
  if (sd == -1)
    ErrorHandling("socket() error");
  memset(&serv_adr, 0, sizeof(serv_adr));
  serv_adr.sin_family = AF_INET;
  serv_adr.sin_addr.s_addr = inet_addr(argv[1]);
  serv_adr.sin_port = htons(atoi(argv[2]));
  if (connect(sd, (struct sockaddr *)&serv_adr, sizeof(serv_adr)) == -1)
    ErrorHandling("connect() error!");
  else
    puts("Conneected......\n");
  while ((read_cnt = read(sd, buf, 1024)) != 0) {
    fwrite((void *)buf, 1, read_cnt, fp);
  }
  puts("Recieved file data");
  fclose(fp);
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1250 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdbf(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x434(%rbp),%rdi
call   10b0 <time@plt>
lea    -0x840(%rbp),%rdi
mov    -0x434(%rbp),%edx
lea    0xda7(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x840(%rbp),%rsi
lea    0xd9b(%rip),%rdi
call   1060 <printf@plt>
lea    -0x840(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12d1 <main+0xc1>
lea    0xd59(%rip),%rdi
call   10e0 <ErrorHandling@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x430(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    134e <main+0x13e>
lea    0xcf0(%rip),%rdi
call   10e0 <ErrorHandling@plt>
jmp    135a <main+0x14a>
lea    0xcf0(%rip),%rdi
call   1030 <puts@plt>
jmp    135f <main+0x14f>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
je     13a2 <main+0x192>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1120 <fwrite@plt>
jmp    135f <main+0x14f>
lea    0xcae(%rip),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x820,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1382 <main+0x172>
lea    0xc(%rsp),%rdi
call   10b0 <time@plt>
mov    0xc(%rsp),%edx
lea    0xdd7(%rip),%rsi
lea    0x420(%rsp),%rbx
mov    %rbx,%rdi
call   10f0 <sprintf@plt>
lea    0xdc7(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
lea    0xdbc(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r12
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    129d <main+0x8d>
lea    0xd8d(%rip),%rdi
call   10e0 <ErrorHandling@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r14),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
je     1301 <main+0xf1>
lea    0xd4b(%rip),%rdi
call   1030 <puts@plt>
jmp    130d <main+0xfd>
lea    0xd2c(%rip),%rdi
call   10e0 <ErrorHandling@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1355 <main+0x145>
lea    0x20(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   1120 <fwrite@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jne    1330 <main+0x120>
lea    0xcfb(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xc74(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"Usage: %s <IP> <port>\0A\00"
@.str.1 = [7 x i8] c"%d.pdf\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@.str.5 = [17 x i8] c"connect() error!\00"
@.str.6 = [18 x i8] c"Conneected......\0A\00"
@.str.7 = [19 x i8] c"Recieved file data\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 [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 @time(i32* %11)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%24 = load i32, i32* %11
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32, i32* @PF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %21
%36 = call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %21
%38 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %39, i32* %40
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @inet_addr(i8* %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
store i32 %44, i32* %46
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = call i32 @htons(i32 %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* %6
%54 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%55 = call i32 @connect(i32 %53, %struct.sockaddr* %54, i32 12)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %37
%58 = call i32 @ErrorHandling(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %61
59: ; preds = %37
%60 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %67, %61
%63 = load i32, i32* %6
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 1024)
store i32 %65, i32* %9
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%69 = load i32, i32* %9
%70 = load i32*, i32** %7
%71 = call i32 @fwrite(i8* %68, i32 1, i32 %69, i32* %70)
br label %62
72: ; preds = %62
%73 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"Usage: %s <IP> <port>\0A\00"
@.str.1 = [7 x i8] c"%d.pdf\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@.str.5 = [17 x i8] c"connect() error!\00"
@.str.6 = [18 x i8] c"Conneected......\0A\00"
@.str.7 = [19 x i8] c"Recieved file data\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = bitcast i32* %5 to i8*
%16 = call i32 @time(i32* %5)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %5
%19 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%21 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @PF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %14
%29 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %30, i32* %31
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %34, i32* %35
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %39, i32* %40
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = call i32 @connect(i32 %24, %struct.sockaddr* %41, i32 12)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %28
%45 = call i32 @ErrorHandling(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %48
46: ; preds = %28
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %44
%49 = call i32 @read(i32 %24, i8* %7, i32 1024)
%50 = icmp eq i32 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %48, %51
%52 = phi i32 [ %54, %51 ], [ %49, %48 ]
%53 = call i32 @fwrite(i8* %7, i32 1, i32 %52, i32* %21)
%54 = call i32 @read(i32 %24, i8* %7, i32 1024)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %51
56: ; preds = %51, %48
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @fclose(i32* %21)
%59 = call i32 @close(i32 %24)
ret i32 0
}