#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 socklen_t;

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


x86 assembly (clang, -O0):
<doit_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x18(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <getsockopt@plt>
cmp    $0x0,%rax
je     1190 <doit_int+0x60>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11aa <doit_int+0x7a>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
movl   $0x4,(%rsp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edx
call   1040 <getsockopt@plt>
test   %rax,%rax
je     1179 <doit_int+0x49>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1050 <fprintf@plt>
jmp    1192 <doit_int+0x62>
mov    (%rsp),%ecx
mov    0x4(%rsp),%r8d
lea    0xe9a(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"getsockopt failed for: %32s (%2d)\00"
@.str.1 = [34 x i8] c"%15s (%2d) optlen=%d value:%6d\0A\00"
define void @doit_int(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 4, 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, i32* %8, i32* %7)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %6
%17 = load i32, i32* %5
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
br label %25
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21, i32 %22, i32 %23)
br label %25
25: ; preds = %19, %14
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"getsockopt failed for: %32s (%2d)\00"
@.str.1 = [34 x i8] c"%15s (%2d) optlen=%d value:%6d\0A\00"
define void @doit_int(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = bitcast i32* %5 to i8*
%8 = load i32, i32* @SOL_SOCKET
%9 = call i64 @getsockopt(i32 %0, i32 %8, i32 %1, i32* %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 ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1)
br label %18
14: ; preds = %3
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %1, i32 %15, i32 %16)
br label %18
18: ; preds = %14, %11
ret void
}