#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int mpl3115_init(int);
int /*<<< orphan*/ reply_heart_beat();
int /*<<< orphan*/ reply_update(int);
int /*<<< orphan*/ sleep(int);
void *task_send(void *arg) {
  int n = 29, k = 9, i2cfd;
  char send_buf[1024];
  i2cfd = mpl3115_init(i2cfd);
  sleep(1);
  while (1) {
    n++;
    k++;
    if (n > 30) {
      n = 0;
      reply_heart_beat();
    }
    if (k > 10) {
      k = 0;
      reply_update(i2cfd);
    }
    sleep(1);
  }
  close(i2cfd);
}


x86 assembly (clang, -O0):
<task_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1d,-0xc(%rbp)
movl   $0x9,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <mpl3115_init@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1e,-0xc(%rbp)
jle    119c <task_send+0x5c>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <reply_heart_beat@plt>
cmpl   $0xa,-0x10(%rbp)
jle    11b5 <task_send+0x75>
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <reply_update@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1172 <task_send+0x32>

x86 assembly (clang, -O2):
<task_send>:
push   %rbp
push   %r14
push   %rbx
call   1030 <mpl3115_init@plt>
mov    %eax,%r14d
mov    $0x1d,%ebp
mov    $0x9,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1060 <sleep@plt>
cmp    $0x1e,%ebp
jge    1180 <task_send+0x40>
add    $0x1,%ebp
jmp    1189 <task_send+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <reply_heart_beat@plt>
lea    0x1(%rbx),%eax
cmp    $0xa,%ebx
mov    %eax,%ebx
jl     1160 <task_send+0x20>
mov    %r14d,%edi
call   1050 <reply_update@plt>
xor    %ebx,%ebx
jmp    1160 <task_send+0x20>

LLVM IR (-O0):
define i8* @task_send(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
store i8* %0, i8** %2
store i32 29, i32* %3
store i32 9, i32* %4
%7 = load i32, i32* %5
%8 = call i32 @mpl3115_init(i32 %7)
store i32 %8, i32* %5
%9 = call i32 @sleep(i32 1)
br label %10
10: ; preds = %1, %25
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 30
br i1 %16, label %17, label %19
17: ; preds = %10
store i32 0, i32* %3
%18 = call i32 (...) @reply_heart_beat()
br label %19
19: ; preds = %17, %10
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %19
store i32 0, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @reply_update(i32 %23)
br label %25
25: ; preds = %22, %19
%26 = call i32 @sleep(i32 1)
br label %10
}

LLVM IR (-O2):
define noalias i8* @task_send(i8* nocapture readnone %0) {
%2 = tail call i32 @mpl3115_init(i32 undef)
br label %3
3: ; preds = %17, %1
%4 = phi i32 [ 9, %1 ], [ %18, %17 ]
%5 = phi i32 [ 29, %1 ], [ %13, %17 ]
%6 = tail call i32 @sleep(i32 1)
%7 = add nsw i32 %5, 1
%8 = add nsw i32 %4, 1
%9 = icmp sgt i32 %5, 29
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 (...) @reply_heart_beat()
br label %12
12: ; preds = %10, %3
%13 = phi i32 [ 0, %10 ], [ %7, %3 ]
%14 = icmp sgt i32 %4, 9
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @reply_update(i32 %2)
br label %17
17: ; preds = %15, %12
%18 = phi i32 [ 0, %15 ], [ %8, %12 ]
br label %3
}