#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_Recv(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 RUDP_GET(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, "GET ", 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);
  int RUDPstatus = 0;
  RUDPstatus =
      RUDP_Recv(sockConn, addrServeServer, filePath, fifo_TOlog, whoIam);
  return RUDPstatus;
}


x86 assembly (clang, -O0):
<RUDP_GET>:
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   1060 <memset@plt>
mov    -0x30(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x60,%edx
call   1080 <strncat@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1070 <sendto@plt>
cmp    $0x0,%rax
jge    1241 <RUDP_GET+0xb1>
lea    0xdd5(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1292 <RUDP_GET+0x102>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1060 <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>
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   1050 <RUDP_Recv@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_GET>:
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,%r13
mov    %rsi,%r12
mov    %edi,%ebp
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    $0x60,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
lea    0xe21(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x60,%edx
call   1080 <strncat@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x4,%r9d
call   1070 <sendto@plt>
test   %rax,%rax
js     1263 <RUDP_GET+0xd3>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x60,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r14,%rdx
mov    (%rsp),%ecx
mov    0x4(%rsp),%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <RUDP_Recv@plt>
lea    0xd9b(%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"GET \00"
@.str.1 = [34 x i8] c"RUDP: Error in SENDTO for CMD PKT\00"
define i32 @RUDP_GET(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 %50
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)
store i32 0, i32* %16
%43 = load i32, i32* %8
%44 = load %struct.sockaddr_in*, %struct.sockaddr_in** %9
%45 = load i8*, i8** %15
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = call i32 @RUDP_Recv(i32 %43, %struct.sockaddr_in* %44, i8* %45, i32 %46, i32 %47)
store i32 %48, i32* %16
%49 = load i32, i32* %16
store i32 %49, i32* %7
br label %50
50: ; preds = %34, %32
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"GET \00"
@.str.1 = [34 x i8] c"RUDP: Error in SENDTO for CMD PKT\00"
define i32 @RUDP_GET(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 %22
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 @RUDP_Recv(i32 %0, %struct.sockaddr_in* %1, i8* %8, i32 %4, i32 %5)
br label %22
22: ; preds = %17, %15
%23 = phi i32 [ 2, %15 ], [ %21, %17 ]
ret i32 %23
}