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

/* Variables and functions */
scalar_t__ send_one(int, struct sockaddr *, int, int);
int tg_npackets(int);
int send_data(int s, struct sockaddr *dst_addr, int addrlen, int len,
              long long duration_s) {
  int i, nr;
  nr = tg_npackets(1000 * duration_s);
  if (nr < 0)
    return -1;
  for (i = 0; i < nr; i++) {
    if (send_one(s, dst_addr, addrlen, len) < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
imul   $0x3e8,-0x20(%rbp),%rax
mov    %eax,%edi
call   1040 <tg_npackets@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1161 <send_data+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <send_data+0x96>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11af <send_data+0x8f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <send_one@plt>
cmp    $0x0,%rax
jge    119c <send_data+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <send_data+0x96>
jmp    11a1 <send_data+0x81>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <send_data+0x48>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r13
mov    %edi,%ebp
imul   $0x3e8,%r8d,%edi
call   1040 <tg_npackets@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     117d <send_data+0x5d>
mov    %eax,%ebx
test   %eax,%eax
je     117a <send_data+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <send_one@plt>
test   %rax,%rax
js     117d <send_data+0x5d>
add    $0xffffffff,%ebx
jne    1160 <send_data+0x40>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
define i32 @send_data(i32 %0, %struct.sockaddr* %1, i32 %2, i32 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store %struct.sockaddr* %1, %struct.sockaddr** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i64 %4, i64* %11
%14 = load i64, i64* %11
%15 = mul nsw i64 1000, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @tg_npackets(i32 %16)
store i32 %17, i32* %13
%18 = load i32, i32* %13
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 -1, i32* %6
br label %39
21: ; preds = %5
store i32 0, i32* %12
br label %22
22: ; preds = %35, %21
%23 = load i32, i32* %12
%24 = load i32, i32* %13
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i32, i32* %7
%28 = load %struct.sockaddr*, %struct.sockaddr** %8
%29 = load i32, i32* %9
%30 = load i32, i32* %10
%31 = call i64 @send_one(i32 %27, %struct.sockaddr* %28, i32 %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 -1, i32* %6
br label %39
34: ; preds = %26
br label %35
35: ; preds = %34
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
br label %22
38: ; preds = %22
store i32 0, i32* %6
br label %39
39: ; preds = %38, %33, %20
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @send_data(i32 %0, %struct.sockaddr* %1, i32 %2, i32 %3, i64 %4) {
%6 = trunc i64 %4 to i32
%7 = mul i32 %6, 1000
%8 = tail call i32 @tg_npackets(i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %5
%11 = icmp eq i32 %8, 0
br i1 %11, label %19, label %14
12: ; preds = %14
%13 = icmp eq i32 %18, %8
br i1 %13, label %19, label %14
14: ; preds = %10, %12
%15 = phi i32 [ %18, %12 ], [ 0, %10 ]
%16 = tail call i64 @send_one(i32 %0, %struct.sockaddr* %1, i32 %2, i32 %3)
%17 = icmp slt i64 %16, 0
%18 = add nuw nsw i32 %15, 1
br i1 %17, label %19, label %12
19: ; preds = %14, %12, %10, %5
%20 = phi i32 [ -1, %5 ], [ 0, %10 ], [ -1, %14 ], [ 0, %12 ]
ret i32 %20
}