#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 */
typedef int uint8_t;
typedef scalar_t__ uint32_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct UdpSocket {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ send_rtp_packet(struct UdpSocket *, int *, scalar_t__,
                                   scalar_t__, scalar_t__, scalar_t__, int, int,
                                   int, int, int, int);
void send_rtp_frame(struct UdpSocket *sock, uint8_t *Jpeg, uint32_t JpegLen,
                    int w, int h, uint8_t format_code, uint8_t quality_code,
                    uint8_t has_dri_header, uint32_t delta_t) {
  static uint32_t packetcounter = 0;
  static uint32_t timecounter = 0;
  uint32_t offset = 0;
  if (delta_t <= 0) {
    struct timeval tv;
    gettimeofday(&tv, 0);
    uint32_t t = (tv.tv_sec % (256 * 256)) * 90000 + tv.tv_usec * 9 / 100;
    timecounter = t;
  }
  for (; JpegLen > 0;) {
    uint32_t len = 1400;
    uint8_t lastpacket = 0;
    if (JpegLen <= len) {
      lastpacket = 1;
      len = JpegLen;
    }
    send_rtp_packet(sock, Jpeg, len, packetcounter, timecounter, offset,
                    lastpacket, w, h, format_code, quality_code,
                    has_dri_header);
    JpegLen -= len;
    Jpeg += len;
    offset += len;
    packetcounter++;
  }
  if (delta_t > 0) {
    timecounter += delta_t;
  }
}


x86 assembly (clang, -O0):
<send_rtp_frame>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %ecx,-0x34(%rbp)
mov    %r8d,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x0,0x20(%rbp)
jg     11a7 <send_rtp_frame+0x87>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x50(%rbp),%eax
mov    $0x10000,%ecx
cltd
idiv   %ecx
imul   $0x15f90,%edx,%eax
mov    %eax,-0x68(%rbp)
imul   $0x9,-0x4c(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,0x2e99(%rip)
jmp    11ac <send_rtp_frame+0x8c>
cmpq   $0x0,-0x30(%rbp)
jle    1279 <send_rtp_frame+0x159>
movq   $0x578,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x60(%rbp),%rax
jg     11e3 <send_rtp_frame+0xc3>
movl   $0x1,-0x64(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    0x2e42(%rip),%rcx
mov    0x2e43(%rip),%r8
mov    -0x48(%rbp),%r9
mov    -0x64(%rbp),%r15d
mov    -0x34(%rbp),%r14d
mov    -0x38(%rbp),%ebx
mov    -0x3c(%rbp),%r11d
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %eax,0x28(%rsp)
call   1030 <send_rtp_packet@plt>
mov    -0x60(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x60(%rbp),%rax
shl    $0x2,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x60(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dcf(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2dc4(%rip)
jmp    11ac <send_rtp_frame+0x8c>
cmpq   $0x0,0x20(%rbp)
jle    1296 <send_rtp_frame+0x176>
mov    0x20(%rbp),%rax
add    0x2db1(%rip),%rax
mov    %rax,0x2daa(%rip)
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_rtp_frame>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r11d
mov    %r8d,%r10d
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
cmpq   $0x0,0x60(%rsp)
jle    1152 <send_rtp_frame+0x32>
test   %r15,%r15
jg     11ba <send_rtp_frame+0x9a>
jmp    1256 <send_rtp_frame+0x136>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %r11,%rbp
mov    %r10,%r14
call   1040 <gettimeofday@plt>
mov    %r14,%r10
mov    %rbp,%r11
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
lea    0xffff(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
and    $0xffff0000,%edx
sub    %edx,%eax
imul   $0x15f90,%eax,%eax
lea    (%rcx,%rcx,8),%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rax
mov    %rax,0x2e8f(%rip)
test   %r15,%r15
jle    1256 <send_rtp_frame+0x136>
mov    0x2e77(%rip),%rcx
xor    %r14d,%r14d
mov    %r13,0x10(%rsp)
nopl   0x0(%rax)
mov    %r15,(%rsp)
xor    %eax,%eax
cmp    $0x579,%r15
setb   %al
mov    $0x578,%r15d
cmovb  (%rsp),%r15
mov    0x2e4e(%rip),%r8
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%r9
mov    0x58(%rsp),%ebp
push   %rbp
mov    0x58(%rsp),%ebp
push   %rbp
push   %r11
push   %r10
push   %r12
push   %rax
mov    %r11,%rbp
mov    %r12,%r13
mov    %r10,%r12
call   1030 <send_rtp_packet@plt>
mov    %r12,%r10
mov    %r13,%r12
mov    0x40(%rsp),%r13
mov    %rbp,%r11
add    $0x30,%rsp
add    %r15,%r14
mov    0x2dff(%rip),%rcx
add    $0x1,%rcx
lea    (%rbx,%r15,4),%rbx
mov    %rcx,0x2df0(%rip)
sub    %r15,(%rsp)
mov    (%rsp),%r15
jg     11d0 <send_rtp_frame+0xb0>
mov    0x60(%rsp),%rax
test   %rax,%rax
jle    1267 <send_rtp_frame+0x147>
add    %rax,0x2dd9(%rip)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.UdpSocket = type { i32 }
%struct.timeval = type { i32, i32 }
@send_rtp_frame.packetcounter = internal global i64 0
@send_rtp_frame.timecounter = internal global i64 0
define void @send_rtp_frame(%struct.UdpSocket* %0, i32* %1, i64 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i64 %8) {
%10 = alloca %struct.UdpSocket*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i64
%20 = alloca %struct.timeval
%21 = alloca i64
%22 = alloca i64
%23 = alloca i32
store %struct.UdpSocket* %0, %struct.UdpSocket** %10
store i32* %1, i32** %11
store i64 %2, i64* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i64 %8, i64* %18
store i64 0, i64* %19
%24 = load i64, i64* %18
%25 = icmp sle i64 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %9
%27 = call i32 @gettimeofday(%struct.timeval* %20, i32 0)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
%29 = load i32, i32* %28
%30 = srem i32 %29, 65536
%31 = mul nsw i32 %30, 90000
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
%33 = load i32, i32* %32
%34 = mul nsw i32 %33, 9
%35 = sdiv i32 %34, 100
%36 = add nsw i32 %31, %35
%37 = sext i32 %36 to i64
store i64 %37, i64* %21
%38 = load i64, i64* %21
store i64 %38, i64* @send_rtp_frame.timecounter
br label %39
39: ; preds = %26, %9
br label %40
40: ; preds = %49, %39
%41 = load i64, i64* %12
%42 = icmp sgt i64 %41, 0
br i1 %42, label %43, label %74
43: ; preds = %40
store i64 1400, i64* %22
store i32 0, i32* %23
%44 = load i64, i64* %12
%45 = load i64, i64* %22
%46 = icmp sle i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
store i32 1, i32* %23
%48 = load i64, i64* %12
store i64 %48, i64* %22
br label %49
49: ; preds = %47, %43
%50 = load %struct.UdpSocket*, %struct.UdpSocket** %10
%51 = load i32*, i32** %11
%52 = load i64, i64* %22
%53 = load i64, i64* @send_rtp_frame.packetcounter
%54 = load i64, i64* @send_rtp_frame.timecounter
%55 = load i64, i64* %19
%56 = load i32, i32* %23
%57 = load i32, i32* %13
%58 = load i32, i32* %14
%59 = load i32, i32* %15
%60 = load i32, i32* %16
%61 = load i32, i32* %17
%62 = call i32 @send_rtp_packet(%struct.UdpSocket* %50, i32* %51, i64 %52, i64 %53, i64 %54, i64 %55, i32 %56, i32 %57, i32 %58, i32 %59, i32 %60, i32 %61)
%63 = load i64, i64* %22
%64 = load i64, i64* %12
%65 = sub nsw i64 %64, %63
store i64 %65, i64* %12
%66 = load i64, i64* %22
%67 = load i32*, i32** %11
%68 = getelementptr inbounds i32, i32* %67, i64 %66
store i32* %68, i32** %11
%69 = load i64, i64* %22
%70 = load i64, i64* %19
%71 = add nsw i64 %70, %69
store i64 %71, i64* %19
%72 = load i64, i64* @send_rtp_frame.packetcounter
%73 = add nsw i64 %72, 1
store i64 %73, i64* @send_rtp_frame.packetcounter
br label %40
74: ; preds = %40
%75 = load i64, i64* %18
%76 = icmp sgt i64 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %74
%78 = load i64, i64* %18
%79 = load i64, i64* @send_rtp_frame.timecounter
%80 = add nsw i64 %79, %78
store i64 %80, i64* @send_rtp_frame.timecounter
br label %81
81: ; preds = %77, %74
ret void
}

LLVM IR (-O2):
%struct.UdpSocket = type { i32 }
%struct.timeval = type { i32, i32 }
@send_rtp_frame.packetcounter = internal unnamed_addr global i64 0
@send_rtp_frame.timecounter = internal unnamed_addr global i64 0
define void @send_rtp_frame(%struct.UdpSocket* %0, i32* %1, i64 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i64 %8) {
%10 = alloca %struct.timeval
%11 = icmp slt i64 %8, 1
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = bitcast %struct.timeval* %10 to i8*
%14 = call i32 @gettimeofday(%struct.timeval* %10, i32 0)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
%16 = load i32, i32* %15
%17 = srem i32 %16, 65536
%18 = mul nsw i32 %17, 90000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
%20 = load i32, i32* %19
%21 = mul nsw i32 %20, 9
%22 = sdiv i32 %21, 100
%23 = add nsw i32 %22, %18
%24 = sext i32 %23 to i64
store i64 %24, i64* @send_rtp_frame.timecounter
br label %25
25: ; preds = %12, %9
%26 = icmp sgt i64 %2, 0
br i1 %26, label %27, label %45
27: ; preds = %25
%28 = load i64, i64* @send_rtp_frame.packetcounter
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ %43, %29 ], [ %28, %27 ]
%31 = phi i32* [ %40, %29 ], [ %1, %27 ]
%32 = phi i64 [ %41, %29 ], [ 0, %27 ]
%33 = phi i64 [ %39, %29 ], [ %2, %27 ]
%34 = icmp ult i64 %33, 1401
%35 = select i1 %34, i64 %33, i64 1400
%36 = zext i1 %34 to i32
%37 = load i64, i64* @send_rtp_frame.timecounter
%38 = call i32 @send_rtp_packet(%struct.UdpSocket* %0, i32* %31, i64 %35, i64 %30, i64 %37, i64 %32, i32 %36, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7)
%39 = sub nsw i64 %33, %35
%40 = getelementptr inbounds i32, i32* %31, i64 %35
%41 = add nsw i64 %35, %32
%42 = load i64, i64* @send_rtp_frame.packetcounter
%43 = add nsw i64 %42, 1
store i64 %43, i64* @send_rtp_frame.packetcounter
%44 = icmp sgt i64 %39, 0
br i1 %44, label %29, label %45
45: ; preds = %29, %25
%46 = icmp sgt i64 %8, 0
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = load i64, i64* @send_rtp_frame.timecounter
%49 = add nsw i64 %48, %8
store i64 %49, i64* @send_rtp_frame.timecounter
br label %50
50: ; preds = %47, %45
ret void
}