#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 */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char getchar();
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Not enough arguments\n");
    exit(0);
  }
  int sockfd, numbytes, i = 0;
  struct sockaddr_in their_addr;
  char buf1[100], msg1[100], ch;
  FILE *fr;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(atoi(argv[2]));
  their_addr.sin_addr.s_addr = inet_addr(argv[1]);
  memset(&(their_addr.sin_zero), '\0', 8);
  connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr));
  printf("Enter the file name ::");
  while ((ch = getchar()) != '\n') {
    msg1[i++] = ch;
  }
  msg1[i] = '\0';
  send(sockfd, msg1, strlen(msg1), 0);
  numbytes = recv(sockfd, buf1, 100 - 1, 0);
  if (strcmp(buf1, "bad_req") == 0) {
    printf("Bad request. File not found\n");
  } else {
    fr = fopen(msg1, "w");
    fputs(buf1, (FILE *)fr);
    printf("recieved:: %s\n", msg1);
    fclose(fr);
  }
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1248 <main+0x38>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1120 <connect@plt>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   10e0 <getchar@plt>
mov    %al,-0x111(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1305 <main+0xf5>
mov    -0x111(%rbp),%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %cl,-0x110(%rbp,%rax,1)
jmp    12cd <main+0xbd>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0x12c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xcbc(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1393 <main+0x183>
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13e1 <main+0x1d1>
lea    -0x110(%rbp),%rdi
lea    0xcb1(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x120(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x120(%rbp),%rsi
call   1090 <fputs@plt>
lea    -0x110(%rbp),%rsi
lea    0xc86(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xe8,%rsp
cmp    $0x2,%edi
jle    138c <main+0x16c>
mov    %rsi,%rbx
mov    0x2da8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%r15d
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10b0 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1130 <connect@plt>
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   10f0 <getchar@plt>
cmp    $0xa,%al
je     12d6 <main+0xb6>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   10f0 <getchar@plt>
cmp    $0xa,%al
jne    12c0 <main+0xa0>
mov    %ebx,%r14d
movb   $0x0,0x10(%rsp,%r14,1)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0x80(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xcfe(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1368 <main+0x148>
lea    0xcf2(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1100 <fopen@plt>
mov    %rax,%rbx
lea    0x80(%rsp),%rdi
mov    %rax,%rsi
call   10a0 <fputs@plt>
lea    0xccd(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1374 <main+0x154>
lea    0xcc1(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   10c0 <close@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb9(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [22 x i8] c"Not enough arguments\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"Enter the file name ::\00"
@.str.2 = [8 x i8] c"bad_req\00"
@.str.3 = [29 x i8] c"Bad request. File not found\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [15 x i8] c"recieved:: %s\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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [100 x i8]
%11 = alloca [100 x i8]
%12 = alloca i8
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
store i32 0, i32* %8
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 3
store i32 %23, i32* %24
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%38 = call i32 @memset(i32* %37, i8 signext 0, i32 8)
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%41 = call i32 @connect(i32 %39, %struct.sockaddr* %40, i32 4)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %47, %19
%44 = call signext i8 (...) @getchar()
store i8 %44, i8* %12
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = load i8, i8* %12
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 %51
store i8 %48, i8* %52
br label %43
53: ; preds = %43
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 %55
store i8 0, i8* %56
%57 = load i32, i32* %6
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%60 = call i32 @strlen(i8* %59)
%61 = call i32 @send(i32 %57, i8* %58, i32 %60, i32 0)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%64 = call i32 @recv(i32 %62, i8* %63, i32 99, i32 0)
store i32 %64, i32* %7
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %53
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %80
70: ; preds = %53
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%72 = call i32* @fopen(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %72, i32** %13
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%74 = load i32*, i32** %13
%75 = call i32 @fputs(i8* %73, i32* %74)
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %76)
%78 = load i32*, i32** %13
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %70, %68
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"Enter the file name ::\00"
@.str.2 = [8 x i8] c"bad_req\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [15 x i8] c"recieved:: %s\0A\00"
@str = [28 x i8] c"Bad request. File not found\00"
@str.6 = [21 x i8] c"Not enough arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 @inet_addr(i8* %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%29 = call i32 @memset(i32* %28, i8 signext 0, i32 8)
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i32 @connect(i32 %16, %struct.sockaddr* %30, i32 4)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%33 = call signext i8 (...) @getchar()
%34 = icmp eq i8 %33, 10
br i1 %34, label %44, label %35
35: ; preds = %10, %35
%36 = phi i64 [ %38, %35 ], [ 0, %10 ]
%37 = phi i8 [ %40, %35 ], [ %33, %10 ]
%38 = add nuw i64 %36, 1
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %36
store i8 %37, i8* %39
%40 = call signext i8 (...) @getchar()
%41 = icmp eq i8 %40, 10
br i1 %41, label %42, label %35
42: ; preds = %35
%43 = and i64 %38, 4294967295
br label %44
44: ; preds = %42, %10
%45 = phi i64 [ 0, %10 ], [ %43, %42 ]
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i32 @strlen(i8* %13)
%48 = call i32 @send(i32 %16, i8* %13, i32 %47, i32 0)
%49 = call i32 @recv(i32 %16, i8* %12, i32 99, i32 0)
%50 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %59
54: ; preds = %44
%55 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @fputs(i8* %12, i32* %55)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%58 = call i32 @fclose(i32* %55)
br label %59
59: ; preds = %54, %52
%60 = call i32 @close(i32 %16)
ret i32 0
}