#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int fd, numbytes;
  char recvbuf[100];
  char sendbuf[100];
  struct hostent *he;
  struct sockaddr_in server, client;
  int yes;
  FILE *file;
  if ((file = fopen("client.c", "r")) == NULL) {
    printf("open out.txt error....\n");
    exit(-1);
  }
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    printf("socket() error\n");
    exit(1);
  }
  bzero(&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_port = htons(1234);
  server.sin_addr.s_addr = inet_addr("192.168.33.11");
  socklen_t len;
  len = sizeof(struct sockaddr_in);
  while (fgets(sendbuf, 100, file)) {
    printf("%s", sendbuf);
    sendto(fd, sendbuf, strlen(sendbuf), 0, (struct sockaddr *)&server, len);
    if ((numbytes = recvfrom(fd, recvbuf, 100, 0, (struct sockaddr *)&server,
                             &len)) == -1) {
      printf("recvfrom() error\n");
      break;
    }
    recvbuf[numbytes] = '\0';
  }
  fclose(file);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rdi
lea    0xe12(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1225 <main+0x55>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1262 <main+0x92>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x108(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,-0x104(%rbp)
lea    0xd9a(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x108(%rbp)
movl   $0xc,-0x12c(%rbp)
lea    -0xf0(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x64,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     137a <main+0x1aa>
lea    -0xf0(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
lea    -0x108(%rbp),%r8
mov    -0x12c(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x108(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x12c(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    136c <main+0x19c>
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    137a <main+0x1aa>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
jmp    12ae <main+0xde>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
lea    0xe08(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     134b <main+0x16b>
mov    %rax,%r15
mov    0x2dd1(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     1361 <main+0x181>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xdab(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1328 <main+0x148>
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0x90(%rsp),%r13
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1080 <sendto@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r14,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x13c>
cltq
movb   $0x0,0x90(%rsp,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    12b0 <main+0xd0>
jmp    1328 <main+0x148>
lea    0xcf7(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xcc3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"client.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"open out.txt error....\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [16 x i8] c"socket() error\0A\00"
@.str.4 = [14 x i8] c"192.168.33.11\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [18 x i8] c"recvfrom() error\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 [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca %struct.hostent*
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %14
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %31, i32* %32
%33 = call i32 @htons(i32 1234)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %33, i32* %34
%35 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
store i32 12, i32* %15
br label %38
38: ; preds = %60, %29
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%40 = load i32*, i32** %14
%41 = call i64 @fgets(i8* %39, i32 100, i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %64
43: ; preds = %38
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %6
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%51 = load i32, i32* %15
%52 = call i32 @sendto(i32 %46, i8* %47, i32 %49, i32 0, %struct.sockaddr* %50, i32 %51)
%53 = load i32, i32* %6
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%55 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%56 = call i32 @recvfrom(i32 %53, i8* %54, i32 100, i32 0, %struct.sockaddr* %55, i32* %15)
store i32 %56, i32* %7
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %43
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %64
60: ; preds = %43
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %62
store i8 0, i8* %63
br label %38
64: ; preds = %58, %38
%65 = load i32*, i32** %14
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [9 x i8] c"client.c\00"
@.str.1 = [2 x i8] c"r\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.4 = [14 x i8] c"192.168.33.11\00"
@.str.5 = [3 x i8] c"%s\00"
@str = [17 x i8] c"recvfrom() error\00"
@str.7 = [15 x i8] c"socket() error\00"
@str.8 = [23 x i8] c"open out.txt error....\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %25, i32* %26
%27 = tail call i32 @htons(i32 1234)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %27, i32* %28
%29 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %29, i32* %30
%31 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%32 = call i64 @fgets(i8* %8, i32 100, i32* %10)
%33 = icmp eq i64 %32, 0
br i1 %33, label %50, label %34
34: ; preds = %23
%35 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %36
36: ; preds = %34, %45
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%38 = call i32 @strlen(i8* %8)
%39 = load i32, i32* %6
%40 = call i32 @sendto(i32 %18, i8* %8, i32 %38, i32 0, %struct.sockaddr* %35, i32 %39)
%41 = call i32 @recvfrom(i32 %18, i8* %7, i32 100, i32 0, %struct.sockaddr* %35, i32* %6)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %50
45: ; preds = %36
%46 = sext i32 %41 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %46
store i8 0, i8* %47
%48 = call i64 @fgets(i8* %8, i32 100, i32* %10)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %36
50: ; preds = %45, %23, %43
%51 = call i32 @fclose(i32* %10)
%52 = call i32 @close(i32 %18)
ret i32 0
}