#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 /*<<< orphan*/ uint8_t;
struct sockaddr_in {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ logger(char *, int, int, char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ send_packet(char *, size_t, int /*<<< orphan*/, size_t, int,
                               int, struct sockaddr_in *);
int strlen(char *);
void send_message(char *str, uint8_t packet_id, int fd,
                  struct sockaddr_in *i8_addr) {
  size_t total_size;
  size_t pkt_size;
  int offset;
  int frag_no;
  int tot_frags;
  total_size = strlen(str) + 1;
  logger("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/"
         "i8-transceiver/test_mode.c",
         120, 100, "Fake node: Sending message (packet_id=%d, total_size=%d)",
         packet_id, total_size);
  tot_frags = total_size / 80;
  for (frag_no = 0; frag_no <= tot_frags; frag_no++) {
    if (frag_no == tot_frags)
      pkt_size = total_size % 80;
    else
      pkt_size = 80;
    offset = frag_no * 80;
    send_packet(str, pkt_size, packet_id, total_size, offset, fd, i8_addr);
  }
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    0xe99(%rip),%rdi
mov    $0x78,%esi
mov    $0x64,%edx
lea    0xf22(%rip),%rcx
call   1040 <logger@plt>
mov    -0x20(%rbp),%rax
mov    $0x50,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jg     1205 <send_message+0xd5>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jne    11c4 <send_message+0x94>
mov    -0x20(%rbp),%rax
mov    $0x50,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
jmp    11cc <send_message+0x9c>
movq   $0x50,-0x28(%rbp)
imul   $0x50,-0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x18(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <send_packet@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1195 <send_message+0x65>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r13
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbx
lea    0xea2(%rip),%rdi
lea    0xf35(%rip),%rcx
mov    $0x78,%esi
mov    $0x64,%edx
mov    %r12d,%r8d
mov    %rbx,%r9
call   1040 <logger@plt>
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rbp
shr    $0x6,%rbp
test   %ebp,%ebp
js     11f4 <send_message+0xc4>
add    $0x1,%ebp
xor    %r14d,%r14d
jmp    11c6 <send_message+0x96>
nopl   (%rax)
mov    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    %r13,%rdi
mov    %r12d,%edx
mov    %rbx,%rcx
mov    %r14d,%r8d
mov    %r15d,%r9d
call   1050 <send_packet@plt>
add    $0x50,%r14d
add    $0xffffffff,%ebp
je     11f4 <send_message+0xc4>
mov    $0x50,%esi
cmp    $0x1,%ebp
jne    11a0 <send_message+0x70>
mov    %rbx,%rax
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mul    %rcx
shr    $0x2,%rdx
and    $0xfffffffffffffff0,%rdx
lea    (%rdx,%rdx,4),%rax
mov    %rbx,%rsi
sub    %rax,%rsi
jmp    11a0 <send_message+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/i8-transceiver/test_mode.c\00"
@.str.1 = [57 x i8] c"Fake node: Sending message (packet_id=%d, total_size=%d)\00"
define void @send_message(i8* %0, i32 %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
store i64 %17, i64* %9
%18 = load i32, i32* %6
%19 = load i64, i64* %9
%20 = call i32 @logger(i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str, i64 0, i64 0), i32 120, i32 100, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %18, i64 %19)
%21 = load i64, i64* %9
%22 = udiv i64 %21, 80
%23 = trunc i64 %22 to i32
store i32 %23, i32* %13
store i32 0, i32* %12
br label %24
24: ; preds = %47, %4
%25 = load i32, i32* %12
%26 = load i32, i32* %13
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = load i32, i32* %12
%30 = load i32, i32* %13
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i64, i64* %9
%34 = urem i64 %33, 80
store i64 %34, i64* %10
br label %36
35: ; preds = %28
store i64 80, i64* %10
br label %36
36: ; preds = %35, %32
%37 = load i32, i32* %12
%38 = mul nsw i32 %37, 80
store i32 %38, i32* %11
%39 = load i8*, i8** %5
%40 = load i64, i64* %10
%41 = load i32, i32* %6
%42 = load i64, i64* %9
%43 = load i32, i32* %11
%44 = load i32, i32* %7
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%46 = call i32 @send_packet(i8* %39, i64 %40, i32 %41, i64 %42, i32 %43, i32 %44, %struct.sockaddr_in* %45)
br label %47
47: ; preds = %36
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %24
50: ; preds = %24
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iGW/byteport-api/refs/heads/master/c/i8-transceiver/test_mode.c\00"
@.str.1 = [57 x i8] c"Fake node: Sending message (packet_id=%d, total_size=%d)\00"
define void @send_message(i8* %0, i32 %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = tail call i32 @logger(i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str, i64 0, i64 0), i32 120, i32 100, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %1, i64 %7)
%9 = udiv i64 %7, 80
%10 = urem i64 %7, 80
%11 = trunc i64 %9 to i32
%12 = icmp slt i32 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %4, %13
%14 = phi i32 [ %19, %13 ], [ 0, %4 ]
%15 = icmp eq i32 %14, %11
%16 = select i1 %15, i64 %10, i64 80
%17 = mul nuw nsw i32 %14, 80
%18 = tail call i32 @send_packet(i8* %0, i64 %16, i32 %1, i64 %7, i32 %17, i32 %2, %struct.sockaddr_in* %3)
%19 = add nuw i32 %14, 1
%20 = icmp eq i32 %14, %11
br i1 %20, label %21, label %13
21: ; preds = %13, %4
ret void
}