#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct timespec {
  int tv_sec;
};
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  struct sockaddr_in *msg_name;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ srv_addr;
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ htons(int);
void *inet_addr(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sem_init(int /*<<< orphan*/ *, int /*<<< orphan*/,
                            int /*<<< orphan*/);
int /*<<< orphan*/ sem_timedwait(int /*<<< orphan*/ *, struct timespec *);
scalar_t__ sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void test_1() {
  char *data;
  int sockfd;
  sem_t lock;
  struct timespec abstime;
  sem_init(&lock, 0, 0);
  data = (char *)malloc(1000);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in srv_addr;
  size_t cli_add_len;
  bzero(&srv_addr, sizeof(srv_addr));
  srv_addr.sin_addr.s_addr = inet_addr("47.92.27.198");
  srv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  srv_addr.sin_port = htons(9958);
  clock_gettime(CLOCK_REALTIME, &abstime);
  for (int i = 1; i <= 120; i++) {
    printf("%2d ", i);
    if (i % 10 == 0)
      printf("\n");
    for (int j = 0; j < 100; j++) {
      struct msghdr msg;
      struct iovec iovec1;
      iovec1.iov_base = data;
      iovec1.iov_len = 1000;
      msg.msg_name = &srv_addr;
      msg.msg_namelen = sizeof(srv_addr);
      msg.msg_iov = &iovec1;
      msg.msg_iovlen = 1;
      ssize_t sended = sendmsg(sockfd, &msg, 0);
      if (sended < 0) {
        printf("sendmsg errno %d\n", errno);
      }
    }
    abstime.tv_sec += 1;
    sem_timedwait(&lock, &abstime);
  }
  close(sockfd);
}


x86 assembly (clang, -O0):
<test_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <sem_init@plt>
mov    $0x3e8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0xc(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10c0 <bzero@plt>
lea    0xdfc(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
lea    0xdf9(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
mov    $0x26e6,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
movl   $0x1,-0x34(%rbp)
cmpl   $0x78,-0x34(%rbp)
jg     1329 <test_1+0x179>
mov    -0x34(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x34(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1280 <test_1+0xd0>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x64,-0x38(%rbp)
jge    1305 <test_1+0x155>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x3e8,-0x58(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x10,-0x50(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jge    12f2 <test_1+0x142>
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12f7 <test_1+0x147>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1287 <test_1+0xd7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <sem_timedwait@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1243 <test_1+0x93>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xc(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <sem_init@plt>
mov    $0x3e8,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
lea    0xde6(%rip),%rdi
call   10a0 <inet_addr@plt>
lea    0xde7(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,0x18(%rsp)
mov    $0x26e6,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <clock_gettime@plt>
mov    $0x1,%ebx
lea    0x20(%rsp),%r13
lea    0x30(%rsp),%r12
jmp    1281 <test_1+0xc1>
addl   $0x1,(%rsp)
lea    0xc(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <sem_timedwait@plt>
mov    0x8(%rsp),%ebx
add    $0x1,%ebx
cmp    $0x79,%ebx
je     1311 <test_1+0x151>
lea    0xd8f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,0x8(%rsp)
imul   $0xffffffcd,%ebx,%eax
ror    %al
cmp    $0x1a,%al
jae    12a8 <test_1+0xe8>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x64,%r15d
movabs $0x100000010,%rbx
jmp    12c6 <test_1+0x106>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%r15d
je     1260 <test_1+0xa0>
mov    %r14,0x20(%rsp)
movl   $0x3e8,0x28(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x40(%rsp)
mov    %rbx,0x30(%rsp)
mov    %r13,0x38(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
test   %rax,%rax
jns    12c0 <test_1+0x100>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
lea    0xd14(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12c0 <test_1+0x100>
mov    %ebp,%edi
call   1090 <close@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr_in* }
%struct.iovec = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"47.92.27.198\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [5 x i8] c"%2d \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [18 x i8] c"sendmsg errno %d\0A\00"
@errno = global i32 0
define void @test_1() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.sockaddr_in
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.msghdr
%10 = alloca %struct.iovec
%11 = alloca i64
%12 = call i32 @sem_init(i32* %3, i32 0, i32 0)
%13 = call i64 @malloc(i32 1000)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %1
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %2
%18 = call i32 @bzero(%struct.sockaddr_in* %5, i32 16)
%19 = call i8* @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i8* %22, i8** %24
%25 = call i32 @htons(i32 9958)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @CLOCK_REALTIME
%28 = call i32 @clock_gettime(i32 %27, %struct.timespec* %4)
store i32 1, i32* %7
br label %29
29: ; preds = %68, %0
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 120
br i1 %31, label %32, label %71
32: ; preds = %29
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %7
%36 = srem i32 %35, 10
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
store i32 0, i32* %8
br label %41
41: ; preds = %60, %40
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 100
br i1 %43, label %44, label %63
44: ; preds = %41
%45 = load i8*, i8** %1
%46 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 0
store i8* %45, i8** %46
%47 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 1
store i32 1000, i32* %47
%48 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 3
store %struct.sockaddr_in* %5, %struct.sockaddr_in** %48
%49 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 0
store i32 16, i32* %49
%50 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 2
store %struct.iovec* %10, %struct.iovec** %50
%51 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %9, i32 0, i32 1
store i32 1, i32* %51
%52 = load i32, i32* %2
%53 = call i64 @sendmsg(i32 %52, %struct.msghdr* %9, i32 0)
store i64 %53, i64* %11
%54 = load i64, i64* %11
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %44
%57 = load i32, i32* @errno
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %44
br label %60
60: ; preds = %59
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %41
63: ; preds = %41
%64 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%65 = load i32, i32* %64
%66 = add nsw i32 %65, 1
store i32 %66, i32* %64
%67 = call i32 @sem_timedwait(i32* %3, %struct.timespec* %4)
br label %68
68: ; preds = %63
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %29
71: ; preds = %29
%72 = load i32, i32* %2
%73 = call i32 @close(i32 %72)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr_in* }
%struct.iovec = type { i8*, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"47.92.27.198\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@CLOCK_REALTIME = global i32 0
@.str.2 = [5 x i8] c"%2d \00"
@.str.4 = [18 x i8] c"sendmsg errno %d\0A\00"
@errno = global i32 0
define void @test_1() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.msghdr
%5 = alloca %struct.iovec
%6 = bitcast i32* %1 to i8*
%7 = bitcast %struct.timespec* %2 to i8*
%8 = call i32 @sem_init(i32* %1, i32 0, i32 0)
%9 = call i64 @malloc(i32 1000)
%10 = inttoptr i64 %9 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @bzero(%struct.sockaddr_in* %3, i32 16)
%16 = call i8* @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%18 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %17
%19 = call i32 @htons(i32 9958)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @CLOCK_REALTIME
%22 = call i32 @clock_gettime(i32 %21, %struct.timespec* %2)
%23 = bitcast %struct.msghdr* %4 to i8*
%24 = bitcast %struct.iovec* %5 to i8*
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
%27 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 3
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 0
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 2
%30 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 1
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
br label %34
32: ; preds = %43
%33 = call i32 @close(i32 %13)
ret void
34: ; preds = %0, %43
%35 = phi i32 [ 1, %0 ], [ %47, %43 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = trunc i32 %35 to i8
%38 = urem i8 %37, 10
%39 = icmp eq i8 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %41, %34
br label %49
41: ; preds = %34
%42 = call i32 @putchar(i32 10)
br label %40
43: ; preds = %56
%44 = load i32, i32* %31
%45 = add nsw i32 %44, 1
store i32 %45, i32* %31
%46 = call i32 @sem_timedwait(i32* %1, %struct.timespec* %2)
%47 = add nuw nsw i32 %35, 1
%48 = icmp eq i32 %47, 121
br i1 %48, label %32, label %34
49: ; preds = %40, %56
%50 = phi i32 [ %57, %56 ], [ 0, %40 ]
store i8* %10, i8** %25
store i32 1000, i32* %26
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %27
store i32 16, i32* %28
store %struct.iovec* %5, %struct.iovec** %29
store i32 1, i32* %30
%51 = call i64 @sendmsg(i32 %13, %struct.msghdr* %4, i32 0)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @errno
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %49
%57 = add nuw nsw i32 %50, 1
%58 = icmp eq i32 %57, 100
br i1 %58, label %43, label %49
}