#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*/ tcp_info;
struct timeval {
  int dummy;
};
struct tcp_info {
  int tcpi_snd_cwnd;
  int tcpi_snd_ssthresh;
  int tcpi_rcv_ssthresh;
  int tcpi_rtt;
  int tcpi_rttvar;
  int tcpi_last_data_sent;
  int tcpi_last_data_recv;
  int tcpi_unacked;
  int tcpi_sacked;
  int tcpi_lost;
  int tcpi_retrans;
  int tcpi_fackets;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int LOG_CRIT;
int LOG_DAEMON;
int /*<<< orphan*/ SOL_TCP;
int /*<<< orphan*/ TCP_INFO;
int /*<<< orphan*/ errno;
scalar_t__ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ get_now(struct timeval *, short);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *,
                      int *);
int /*<<< orphan*/ printf(char *, int, int, int, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int, char *, char *);
double time_to_seconds(struct timeval *, struct timeval *);
int stat_update(int sockfd, FILE *statistics, struct timeval *time_start,
                short int opt_debug) {
  struct timeval time_fin;
  get_now(&time_fin, opt_debug);
  struct tcp_info tcp_info;
  socklen_t tcp_info_length = sizeof(tcp_info);
  if (getsockopt(sockfd, SOL_TCP, TCP_INFO, (void *)&tcp_info,
                 (socklen_t *)&tcp_info_length) == 0) {
    if (opt_debug > 0) {
      printf("snd_cwnd: %u\nsnd_ssthresh: %u\nrcv_ssthresh: %u\nrtt: "
             "%u\nrtt_var: %u\n",
             tcp_info.tcpi_snd_cwnd, tcp_info.tcpi_snd_ssthresh,
             tcp_info.tcpi_rcv_ssthresh, tcp_info.tcpi_rtt,
             tcp_info.tcpi_rttvar);
    }
    fprintf(statistics, "%.6f %u %u %u %u %u %u %u %u %u %u %u %u\n",
            time_to_seconds(time_start, &time_fin),
            tcp_info.tcpi_last_data_sent, tcp_info.tcpi_last_data_recv,
            tcp_info.tcpi_snd_cwnd, tcp_info.tcpi_snd_ssthresh,
            tcp_info.tcpi_rcv_ssthresh, tcp_info.tcpi_rtt, tcp_info.tcpi_rttvar,
            tcp_info.tcpi_unacked, tcp_info.tcpi_sacked, tcp_info.tcpi_lost,
            tcp_info.tcpi_retrans, tcp_info.tcpi_fackets);
    if (fflush(statistics) != 0) {
      if (opt_debug > 0) {
        fprintf(stderr, "Cannot flush buffers: %s\n", strerror(errno));
      } else {
        syslog(LOG_DAEMON | LOG_CRIT, "Cannot flush buffers: %s",
               strerror(errno));
      }
    }
  }
}


x86 assembly (clang, -O0):
<stat_update>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %cx,%ax
mov    %edi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %ax,-0x42(%rbp)
lea    -0x48(%rbp),%rdi
movswl -0x42(%rbp),%esi
call   1090 <get_now@plt>
movl   $0x30,-0x7c(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
lea    -0x78(%rbp),%rcx
lea    -0x7c(%rbp),%r8
call   1050 <getsockopt@plt>
cmp    $0x0,%rax
jne    1324 <stat_update+0x1a4>
movswl -0x42(%rbp),%eax
cmp    $0x0,%eax
jle    1210 <stat_update+0x90>
mov    -0x78(%rbp),%esi
mov    -0x74(%rbp),%edx
mov    -0x70(%rbp),%ecx
mov    -0x6c(%rbp),%r8d
mov    -0x68(%rbp),%r9d
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %eax,-0x80(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <time_to_seconds@plt>
mov    -0x80(%rbp),%edi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x78(%rbp),%r8d
mov    -0x74(%rbp),%r9d
mov    -0x70(%rbp),%r13d
mov    -0x6c(%rbp),%r12d
mov    -0x68(%rbp),%r15d
mov    -0x5c(%rbp),%r14d
mov    -0x58(%rbp),%ebx
mov    -0x54(%rbp),%r11d
mov    -0x50(%rbp),%r10d
mov    -0x4c(%rbp),%eax
lea    0xdea(%rip),%rsi
mov    %r13d,(%rsp)
mov    %r12d,0x8(%rsp)
mov    %r15d,0x10(%rsp)
mov    %r14d,0x18(%rsp)
mov    %ebx,0x20(%rsp)
mov    %r11d,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %eax,0x38(%rsp)
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fflush@plt>
cmp    $0x0,%rax
je     131f <stat_update+0x19f>
movswl -0x42(%rbp),%eax
cmp    $0x0,%eax
jle    12df <stat_update+0x15f>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rdx
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    131a <stat_update+0x19a>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    0x2cf1(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x88(%rbp)
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xd73(%rip),%rsi
call   1080 <syslog@plt>
jmp    131f <stat_update+0x19f>
jmp    1324 <stat_update+0x1a4>
mov    -0x2c(%rbp),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_update>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsp,%rdi
mov    %ecx,%esi
call   1090 <get_now@plt>
movl   $0x30,0x4(%rsp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %ebp,%edi
call   1050 <getsockopt@plt>
test   %rax,%rax
je     11e1 <stat_update+0x61>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %bx,%bx
jle    1208 <stat_update+0x88>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <time_to_seconds@plt>
mov    0x1c(%rsp),%edx
mov    0x20(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    0x10(%rsp),%eax
mov    %rax,0x40(%rsp)
mov    0x14(%rsp),%eax
mov    %rax,0x38(%rsp)
mov    0x18(%rsp),%r15d
mov    0x24(%rsp),%r12d
mov    0x28(%rsp),%r13d
mov    0x2c(%rsp),%ebp
mov    0x30(%rsp),%r10d
mov    0x34(%rsp),%r11d
lea    0xde9(%rip),%rsi
mov    %r14d,%edi
mov    $0x1,%al
push   %r11
push   %r10
push   %rbp
push   %r13
push   %r12
push   %r15
push   0x68(%rsp)
push   0x78(%rsp)
call   1060 <fprintf@plt>
add    $0x40,%rsp
mov    %r14,%rdi
call   1070 <fflush@plt>
test   %rax,%rax
je     11d2 <stat_update+0x52>
test   %bx,%bx
jle    12c1 <stat_update+0x141>
mov    0x2d2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdbe(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d2 <stat_update+0x52>
mov    0x2d20(%rip),%rax
mov    0x2d11(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xda0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <syslog@plt>
jmp    11d2 <stat_update+0x52>

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.tcp_info = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@SOL_TCP = global i32 0
@TCP_INFO = global i32 0
@.str = [68 x i8] c"snd_cwnd: %u\0Asnd_ssthresh: %u\0Arcv_ssthresh: %u\0Artt: %u\0Artt_var: %u\0A\00"
@.str.1 = [42 x i8] c"%.6f %u %u %u %u %u %u %u %u %u %u %u %u\0A\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Cannot flush buffers: %s\0A\00"
@errno = global i32 0
@LOG_DAEMON = global i32 0
@LOG_CRIT = global i32 0
@.str.3 = [25 x i8] c"Cannot flush buffers: %s\00"
define i32 @stat_update(i32 %0, i32* %1, %struct.timeval* %2, i16 signext %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.timeval*
%9 = alloca i16
%10 = alloca %struct.timeval
%11 = alloca %struct.tcp_info
%12 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store %struct.timeval* %2, %struct.timeval** %8
store i16 %3, i16* %9
%13 = load i16, i16* %9
%14 = call i32 @get_now(%struct.timeval* %10, i16 signext %13)
store i32 48, i32* %12
%15 = load i32, i32* %6
%16 = load i32, i32* @SOL_TCP
%17 = load i32, i32* @TCP_INFO
%18 = bitcast %struct.tcp_info* %11 to i8*
%19 = call i64 @getsockopt(i32 %15, i32 %16, i32 %17, i8* %18, i32* %12)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %88
21: ; preds = %4
%22 = load i16, i16* %9
%23 = sext i16 %22 to i32
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 3
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 4
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %29, i32 %31, i32 %33, i32 %35)
br label %37
37: ; preds = %25, %21
%38 = load i32*, i32** %7
%39 = ptrtoint i32* %38 to i32
%40 = load %struct.timeval*, %struct.timeval** %8
%41 = call double @time_to_seconds(%struct.timeval* %40, %struct.timeval* %10)
%42 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 5
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 6
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 0
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 2
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 3
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 4
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 7
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 8
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 9
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 10
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %11, i32 0, i32 11
%65 = load i32, i32* %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %41, i32 %43, i32 %45, i32 %47, i32 %49, i32 %51, i32 %53, i32 %55, i32 %57, i32 %59, i32 %61, i32 %63, i32 %65)
%67 = load i32*, i32** %7
%68 = call i64 @fflush(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %87
70: ; preds = %37
%71 = load i16, i16* %9
%72 = sext i16 %71 to i32
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %77)
br label %86
79: ; preds = %70
%80 = load i32, i32* @LOG_DAEMON
%81 = load i32, i32* @LOG_CRIT
%82 = or i32 %80, %81
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 @syslog(i32 %82, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %79, %74
br label %87
87: ; preds = %86, %37
br label %88
88: ; preds = %87, %4
%89 = load i32, i32* %5
ret i32 %89
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tcp_info = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@SOL_TCP = global i32 0
@TCP_INFO = global i32 0
@.str = [68 x i8] c"snd_cwnd: %u\0Asnd_ssthresh: %u\0Arcv_ssthresh: %u\0Artt: %u\0Artt_var: %u\0A\00"
@.str.1 = [42 x i8] c"%.6f %u %u %u %u %u %u %u %u %u %u %u %u\0A\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Cannot flush buffers: %s\0A\00"
@errno = global i32 0
@LOG_DAEMON = global i32 0
@LOG_CRIT = global i32 0
@.str.3 = [25 x i8] c"Cannot flush buffers: %s\00"
define i32 @stat_update(i32 %0, i32* %1, %struct.timeval* %2, i16 signext %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.tcp_info
%7 = alloca i32
%8 = bitcast %struct.timeval* %5 to i8*
%9 = call i32 @get_now(%struct.timeval* %5, i16 signext %3)
%10 = bitcast %struct.tcp_info* %6 to i8*
%11 = bitcast i32* %7 to i8*
store i32 48, i32* %7
%12 = load i32, i32* @SOL_TCP
%13 = load i32, i32* @TCP_INFO
%14 = call i64 @getsockopt(i32 %0, i32 %12, i32 %13, i8* %10, i32* %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %74
16: ; preds = %4
%17 = icmp sgt i16 %3, 0
br i1 %17, label %18, label %30
18: ; preds = %16
%19 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 3
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 4
%28 = load i32, i32* %27
%29 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %26, i32 %28)
br label %30
30: ; preds = %18, %16
%31 = ptrtoint i32* %1 to i64
%32 = trunc i64 %31 to i32
%33 = call double @time_to_seconds(%struct.timeval* %2, %struct.timeval* %5)
%34 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 5
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 6
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 0
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 3
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 4
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 7
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 8
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 9
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 10
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.tcp_info, %struct.tcp_info* %6, i64 0, i32 11
%57 = load i32, i32* %56
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %33, i32 %35, i32 %37, i32 %39, i32 %41, i32 %43, i32 %45, i32 %47, i32 %49, i32 %51, i32 %53, i32 %55, i32 %57)
%59 = call i64 @fflush(i32* %1)
%60 = icmp eq i64 %59, 0
br i1 %60, label %74, label %61
61: ; preds = %30
br i1 %17, label %62, label %67
62: ; preds = %61
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %65)
br label %74
67: ; preds = %61
%68 = load i32, i32* @LOG_DAEMON
%69 = load i32, i32* @LOG_CRIT
%70 = or i32 %69, %68
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 @syslog(i32 %70, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %30, %67, %62, %4
ret i32 undef
}