#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 linger {
  int l_onoff;
  int l_linger;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *,
                      int *);
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int sock_fd, length;
  struct linger l;
  if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    (void)fprintf(stderr, "ERROR   : Failed to create socket() : %s\n",
                  strerror(errno));
    exit(-1);
  }
  length = sizeof(struct linger);
  if (getsockopt(sock_fd, SOL_SOCKET, SO_LINGER, (char *)&l, &length) < 0) {
    (void)fprintf(stderr, "ERROR   : getsockopt() error : %s\n",
                  strerror(errno));
    exit(-1);
  }
  (void)printf("l_onoff = %d\nl_linger = %d\n", l.l_onoff, l.l_linger);
  l.l_onoff = 1;
  l.l_linger = 100;
  if (setsockopt(sock_fd, SOL_SOCKET, SO_LINGER, (char *)&l,
                 sizeof(struct linger)) < 0) {
    (void)fprintf(stderr, "ERROR   : setsockopt() error : %s\n",
                  strerror(errno));
    exit(-1);
  }
  length = sizeof(struct linger);
  if (getsockopt(sock_fd, SOL_SOCKET, SO_LINGER, (char *)&l, &length) < 0) {
    (void)fprintf(stderr, "ERROR   : getsockopt() error : %s\n",
                  strerror(errno));
    exit(-1);
  }
  (void)printf("l_onoff = %d\nl_linger = %d\n", l.l_onoff, l.l_linger);
  (void)close(sock_fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ea <main+0x6a>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe25(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
movl   $0x8,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1060 <getsockopt@plt>
cmp    $0x0,%rax
jge    1253 <main+0xd3>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xde6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
movl   $0x64,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12d7 <main+0x157>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xda1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
movl   $0x8,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1060 <getsockopt@plt>
cmp    $0x0,%rax
jge    1340 <main+0x1c0>
mov    0x2cb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xcf9(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xd00(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
jns    11c9 <main+0x49>
mov    0x2e1b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe3c(%rip),%rsi
jmp    1297 <main+0x117>
mov    %eax,%ebx
movl   $0x8,0xc(%rsp)
mov    0x2e0e(%rip),%r14
mov    (%r14),%esi
mov    0x2df4(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
mov    %eax,%edi
call   1060 <getsockopt@plt>
test   %rax,%rax
js     1279 <main+0xf9>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
movabs $0x6400000001,%rax
mov    %rax,(%rsp)
mov    (%r14),%esi
mov    (%r15),%edx
mov    %rsp,%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jns    1257 <main+0xd7>
mov    0x2d8a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe14(%rip),%rsi
jmp    1297 <main+0x117>
movl   $0x8,0xc(%rsp)
mov    (%r14),%esi
mov    (%r15),%edx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
mov    %ebx,%edi
call   1060 <getsockopt@plt>
test   %rax,%rax
jns    12ab <main+0x12b>
mov    0x2d48(%rip),%rax
mov    (%rax),%ebx
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd93(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xd94(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.linger = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"ERROR : Failed to create socket() : %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.1 = [35 x i8] c"ERROR : getsockopt() error : %s\0A\00"
@.str.2 = [28 x i8] c"l_onoff = %d\0Al_linger = %d\0A\00"
@.str.3 = [35 x i8] c"ERROR : setsockopt() error : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.linger
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
store i32 8, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_LINGER
%19 = bitcast %struct.linger* %4 to i8*
%20 = call i64 @getsockopt(i32 %16, i32 %17, i32 %18, i8* %19, i32* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %15
%29 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
%34 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 0
store i32 1, i32* %34
%35 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 1
store i32 100, i32* %35
%36 = load i32, i32* %2
%37 = load i32, i32* @SOL_SOCKET
%38 = load i32, i32* @SO_LINGER
%39 = bitcast %struct.linger* %4 to i8*
%40 = call i64 @setsockopt(i32 %36, i32 %37, i32 %38, i8* %39, i32 8)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %28
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %28
store i32 8, i32* %3
%49 = load i32, i32* %2
%50 = load i32, i32* @SOL_SOCKET
%51 = load i32, i32* @SO_LINGER
%52 = bitcast %struct.linger* %4 to i8*
%53 = call i64 @getsockopt(i32 %49, i32 %50, i32 %51, i8* %52, i32* %3)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %48
%62 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 0
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.linger, %struct.linger* %4, i32 0, i32 1
%65 = load i32, i32* %64
%66 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %63, i32 %65)
%67 = load i32, i32* %2
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.linger = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"ERROR : Failed to create socket() : %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.1 = [35 x i8] c"ERROR : getsockopt() error : %s\0A\00"
@.str.2 = [28 x i8] c"l_onoff = %d\0Al_linger = %d\0A\00"
@.str.3 = [35 x i8] c"ERROR : setsockopt() error : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.linger
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.linger* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
store i32 8, i32* %1
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_LINGER
%18 = call i64 @getsockopt(i32 %7, i32 %16, i32 %17, i8* %4, i32* %1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %15
%27 = getelementptr inbounds %struct.linger, %struct.linger* %2, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.linger, %struct.linger* %2, i64 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %30)
store i32 1, i32* %27
store i32 100, i32* %29
%32 = load i32, i32* @SOL_SOCKET
%33 = load i32, i32* @SO_LINGER
%34 = call i64 @setsockopt(i32 %7, i32 %32, i32 %33, i8* %4, i32 8)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %26
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %26
store i32 8, i32* %1
%43 = load i32, i32* @SOL_SOCKET
%44 = load i32, i32* @SO_LINGER
%45 = call i64 @getsockopt(i32 %7, i32 %43, i32 %44, i8* %4, i32* %1)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %42
%54 = load i32, i32* %27
%55 = load i32, i32* %29
%56 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55)
%57 = call i32 @close(i32 %7)
%58 = call i32 @exit(i32 0)
unreachable
}