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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int, struct timeval *, int *);
int /*<<< orphan*/ printf(char *, char *, int, int, int, int);
int /*<<< orphan*/ stderr;
void doit_timeval(int sd, int optname, char *name) {
  socklen_t optlen = sizeof(struct timeval);
  struct timeval val;
  if (getsockopt(sd, SOL_SOCKET, optname, &val, &optlen))
    fprintf(stderr, "getsockopt failed for: %32s", name);
  else
    printf("%15s (%2d)  optlen=%d  value: %d secs %d usecs\n", name, optname,
           optlen, (int)val.tv_sec, (int)val.tv_usec);
}


x86 assembly (clang, -O0):
<doit_timeval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x10,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x28(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <getsockopt@plt>
cmp    $0x0,%rax
je     118d <doit_timeval+0x5d>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11b1 <doit_timeval+0x81>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %eax,%r8d
mov    -0x28(%rbp),%rax
mov    %eax,%r9d
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit_timeval>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
movl   $0x10,0x4(%rsp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %ebp,%edx
call   1040 <getsockopt@plt>
test   %rax,%rax
je     117c <doit_timeval+0x4c>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
jmp    119b <doit_timeval+0x6b>
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r9d
mov    0x10(%rsp),%r8d
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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