#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*/ val;
struct timeval {
  int tv_sec;
  int tv_usec;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ err_ret(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getsockopt(int, int /*<<< orphan*/, int, struct timeval *, int *);
int /*<<< orphan*/ printf(char *, char const *, int, int, int);
void print_tm_sockopt(int fd, char const *optstr, int option) {
  struct timeval val;
  socklen_t len = sizeof(val);
  int ret = getsockopt(fd, SOL_SOCKET, option, &val, &len);
  if (ret < 0) {
    err_ret("getsockopt for %s failed, errno %d", optstr, errno);
    return;
  }
  printf("%s [%d]: %d, %d\n", optstr, len, val.tv_sec, val.tv_usec);
}


x86 assembly (clang, -O0):
<print_tm_sockopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1040 <getsockopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1190 <print_tm_sockopt+0x60>
mov    -0x10(%rbp),%rsi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
lea    0xe7a(%rip),%rdi
call   1050 <err_ret@plt>
jmp    11aa <print_tm_sockopt+0x7a>
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_tm_sockopt>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x8,0x4(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1040 <getsockopt@plt>
test   %eax,%eax
js     117a <print_tm_sockopt+0x4a>
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xeb3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1192 <print_tm_sockopt+0x62>
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
call   1050 <err_ret@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@.str = [35 x i8] c"getsockopt for %s failed, errno %d\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"%s [%d]: %d, %d\0A\00"
define void @print_tm_sockopt(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 8, i32* %8
%10 = load i32, i32* %4
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* %6
%13 = call i32 @getsockopt(i32 %10, i32 %11, i32 %12, %struct.timeval* %7, i32* %8)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i32, i32* @errno
%19 = call i32 @err_ret(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
br label %28
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = load i32, i32* %8
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22, i32 %24, i32 %26)
br label %28
28: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@SOL_SOCKET = global i32 0
@.str = [35 x i8] c"getsockopt for %s failed, errno %d\00"
@errno = global i32 0
@.str.1 = [17 x i8] c"%s [%d]: %d, %d\0A\00"
define void @print_tm_sockopt(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%8 = load i32, i32* @SOL_SOCKET
%9 = call i32 @getsockopt(i32 %0, i32 %8, i32 %2, %struct.timeval* %4, i32* %5)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = call i32 @err_ret(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %12)
br label %21
14: ; preds = %3
%15 = load i32, i32* %5
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %15, i32 %17, i32 %19)
br label %21
21: ; preds = %14, %11
ret void
}