#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;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int RUDP_Send(int, struct sockaddr_in *, char *, int, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usleep(int);
int RUDP_PUT(int sockConn, struct sockaddr_in *addrServeServer, char *path,
             char *fileRequested, int fifo_TOlog, int whoIam) {
  char *cmdPkt = malloc(100 * sizeof(char));
  char *filePath = malloc(96 * sizeof(char));
  memset(cmdPkt, 0, 100);
  strncpy(cmdPkt, "PUT ", 4);
  strncat(cmdPkt, fileRequested, 96);
  if (sendto(sockConn, cmdPkt, 100, 0, (struct sockaddr *)addrServeServer,
             sizeof(*addrServeServer)) < 0) {
    perror("RUDP: Error in SENDTO for CMD PKT");
    return 2;
  }
  memset(filePath, 0, 96);
  strcpy(filePath, path);
  strcat(filePath, fileRequested);
  usleep(5000);
  int ret = 0;
  ret = RUDP_Send(sockConn, addrServeServer, filePath, fifo_TOlog, whoIam);
  return ret;
}


x86 assembly (clang, -O0):
<RUDP_PUT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x60,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x60,%edx
call   1070 <strncat@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    1251 <RUDP_PUT+0xb1>
lea    0xdc5(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ac <RUDP_PUT+0x10c>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1050 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strcat@plt>
mov    $0x1388,%edi
call   10c0 <usleep@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1080 <RUDP_Send@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RUDP_PUT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r13d
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    $0x60,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    0xe10(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x60,%edx
call   1070 <strncat@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x4,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
js     1280 <RUDP_PUT+0xe0>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1050 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    $0x1388,%edi
call   10c0 <usleep@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    (%rsp),%ecx
mov    0x4(%rsp),%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <RUDP_Send@plt>
lea    0xd7e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"PUT \00"
@.str.1 = [34 x i8] c"RUDP: Error in SENDTO for CMD PKT\00"
define i32 @RUDP_PUT(i32 %0, %struct.sockaddr_in* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store i32 %0, i32* %8
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%17 = call i8* @malloc(i32 100)
store i8* %17, i8** %14
%18 = call i8* @malloc(i32 96)
store i8* %18, i8** %15
%19 = load i8*, i8** %14
%20 = call i32 @memset(i8* %19, i32 0, i32 100)
%21 = load i8*, i8** %14
%22 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = load i8*, i8** %14
%24 = load i8*, i8** %11
%25 = call i32 @strncat(i8* %23, i8* %24, i32 96)
%26 = load i32, i32* %8
%27 = load i8*, i8** %14
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%29 = bitcast %struct.sockaddr_in* %28 to %struct.sockaddr*
%30 = call i64 @sendto(i32 %26, i8* %27, i32 100, i32 0, %struct.sockaddr* %29, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %6
%33 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %7
br label %51
34: ; preds = %6
%35 = load i8*, i8** %15
%36 = call i32 @memset(i8* %35, i32 0, i32 96)
%37 = load i8*, i8** %15
%38 = load i8*, i8** %10
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = load i8*, i8** %15
%41 = load i8*, i8** %11
%42 = call i32 @strcat(i8* %40, i8* %41)
%43 = call i32 @usleep(i32 5000)
store i32 0, i32* %16
%44 = load i32, i32* %8
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%46 = load i8*, i8** %15
%47 = load i32, i32* %12
%48 = load i32, i32* %13
%49 = call i32 @RUDP_Send(i32 %44, %struct.sockaddr_in* %45, i8* %46, i32 %47, i32 %48)
store i32 %49, i32* %16
%50 = load i32, i32* %16
store i32 %50, i32* %7
br label %51
51: ; preds = %34, %32
%52 = load i32, i32* %7
ret i32 %52
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"PUT \00"
@.str.1 = [34 x i8] c"RUDP: Error in SENDTO for CMD PKT\00"
define i32 @RUDP_PUT(i32 %0, %struct.sockaddr_in* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%8 = tail call dereferenceable_or_null(96) i8* @malloc(i32 96)
%9 = tail call i32 @memset(i8* %7, i32 0, i32 100)
%10 = tail call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = tail call i32 @strncat(i8* %7, i8* %3, i32 96)
%12 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%13 = tail call i64 @sendto(i32 %0, i8* %7, i32 100, i32 0, %struct.sockaddr* %12, i32 4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %23
17: ; preds = %6
%18 = tail call i32 @memset(i8* %8, i32 0, i32 96)
%19 = tail call i32 @strcpy(i8* %8, i8* %2)
%20 = tail call i32 @strcat(i8* %8, i8* %3)
%21 = tail call i32 @usleep(i32 5000)
%22 = tail call i32 @RUDP_Send(i32 %0, %struct.sockaddr_in* %1, i8* %8, i32 %4, i32 %5)
br label %23
23: ; preds = %17, %15
%24 = phi i32 [ 2, %15 ], [ %22, %17 ]
ret i32 %24
}