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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strtok(char *, char *);
void net_recv_write(int soc, struct sockaddr_in *sockaddr) {
  ssize_t num_recv;
  FILE *fd;
  char rbufp[1024];
  char newfile[256];
  char *tok;
  char *ios;
  fd = fopen("./log/log.txt", "w");
  while (1) {
    num_recv = recvfrom(soc, rbufp, 1024, 0, NULL, NULL);
    if (num_recv == -1) {
      perror("recv");
      close(soc);
      exit(EXIT_FAILURE);
    }
    fprintf(fd, "%s", rbufp);
    if (!strncmp(rbufp, "88", 2)) {
      fflush(fd);
      fclose(fd);
      tok = strtok(rbufp, "\t");
      tok = strtok(NULL, "\t");
      ios = strtok(NULL, "\t\n");
      ios = strtok(NULL, "\t\n");
      strcpy(newfile, "log-");
      strcat(newfile, ios);
      strcat(newfile, "-");
      strcat(newfile, tok);
      strcat(newfile, ".txt");
      rename("./log/log.txt", newfile);
      fd = fopen("./log/log.txt", "w");
    }
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<net_recv_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe17(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1246 <net_recv_write+0x76>
lea    0xde5(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xdbd(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1378 <net_recv_write+0x1a8>
mov    -0x20(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x420(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x528(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd66(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x528(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd51(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x530(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3a(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x530(%rbp)
lea    -0x520(%rbp),%rdi
lea    0xd23(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x520(%rbp),%rdi
mov    -0x530(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x520(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x520(%rbp),%rdi
mov    -0x528(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x520(%rbp),%rdi
lea    0xcc0(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x520(%rbp),%rsi
lea    0xca4(%rip),%rdi
call   10d0 <rename@plt>
lea    0xc98(%rip),%rdi
lea    0xc9f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11f9 <net_recv_write+0x29>

x86 assembly (clang, -O2):
<net_recv_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x508,%rsp
mov    %edi,%r15d
lea    0xe15(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
lea    0x100(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    123e <net_recv_write+0x6e>
lea    0xded(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0x100(%rsp),%r14
lea    0xdc8(%rip),%rbx
mov    %rsp,%r13
jmp    127d <net_recv_write+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     121c <net_recv_write+0x4c>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <fputs@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1260 <net_recv_write+0x90>
mov    %r12,%rdi
call   1080 <fflush@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
lea    0xd62(%rip),%rbp
mov    %rbp,%rsi
call   10c0 <strtok@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
lea    0xd46(%rip),%rbp
mov    %rbp,%rsi
call   10c0 <strtok@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   10c0 <strtok@plt>
mov    %rbx,%rbp
mov    %rax,%rbx
mov    %r13,%rdi
lea    0xd27(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rbx
call   10e0 <strcat@plt>
mov    %r13,%rdi
lea    0xd0d(%rip),%rsi
call   10e0 <strcat@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10e0 <strcat@plt>
mov    %r13,%rdi
lea    0xcdc(%rip),%rsi
call   10e0 <strcat@plt>
lea    0xcc7(%rip),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   10d0 <rename@plt>
mov    %rbp,%rdi
lea    0xcc0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
jmp    1260 <net_recv_write+0x90>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [14 x i8] c"./log/log.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"recv\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"88\00"
@.str.5 = [2 x i8] c"\09\00"
@.str.6 = [3 x i8] c"\09\0A\00"
@.str.7 = [5 x i8] c"log-\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [5 x i8] c".txt\00"
define void @net_recv_write(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca [256 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%11 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %2, %56
%13 = load i32, i32* %3
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32 @recvfrom(i32 %13, i8* %14, i32 1024, i32 0, i32* null, i32* null)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %12
%25 = load i32*, i32** %6
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = call i32 @strncmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%30 = icmp ne i32 %29, 0
br i1 %30, label %56, label %31
31: ; preds = %24
%32 = load i32*, i32** %6
%33 = call i32 @fflush(i32* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %37, i8** %9
%38 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %38, i8** %9
%39 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i8* %39, i8** %10
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i8* %40, i8** %10
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = load i8*, i8** %10
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%49 = load i8*, i8** %9
%50 = call i32 @strcat(i8* %48, i8* %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%54 = call i32 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %53)
%55 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %55, i32** %6
br label %56
56: ; preds = %31, %24
br label %12
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [14 x i8] c"./log/log.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"recv\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [3 x i8] c"88\00"
@.str.5 = [2 x i8] c"\09\00"
@.str.6 = [3 x i8] c"\09\0A\00"
@.str.7 = [5 x i8] c"log-\00"
@.str.8 = [2 x i8] c"-\00"
@.str.9 = [5 x i8] c".txt\00"
define void @net_recv_write(i32 %0, %struct.sockaddr_in* nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @recvfrom(i32 %0, i8* %5, i32 1024, i32 0, i32* null, i32* null)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %34, %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @close(i32 %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2, %34
%16 = phi i32* [ %35, %34 ], [ %7, %2 ]
%17 = call i32 @fputs(i8* %5, i32* %16)
%18 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = call i32 @fflush(i32* %16)
%22 = call i32 @fclose(i32* %16)
%23 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%28 = call i32 @strcat(i8* %6, i8* %26)
%29 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%30 = call i32 @strcat(i8* %6, i8* %24)
%31 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 @rename(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %6)
%33 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %20, %15
%35 = phi i32* [ %16, %15 ], [ %33, %20 ]
%36 = call i32 @recvfrom(i32 %0, i8* %5, i32 1024, i32 0, i32* null, i32* null)
%37 = icmp eq i32 %36, -1
br i1 %37, label %10, label %15
}