#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*/ uc;
typedef scalar_t__ u_char;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ err(int, char *, char const *, char const *);
int /*<<< orphan*/ errx(int, char *, char const *, char const *, scalar_t__,
                        scalar_t__);
int getsockopt(int, int /*<<< orphan*/, int, scalar_t__ *, int *);
int setsockopt(int, int /*<<< orphan*/, int, scalar_t__ *, int);
int /*<<< orphan*/ warnx(char *, char const *, char const *);
void test_u_char(int optname, const char *optstring, u_char defaultv,
                 u_char modifiedv, u_char fakev, const char *socktype, int sock,
                 int flags) {
  socklen_t socklen;
  u_char uc;
  int ret;
  uc = fakev;
  socklen = sizeof(uc);
  ret = getsockopt(sock, IPPROTO_IP, optname, &uc, &socklen);
  if (ret < 0)
    err(-1, "FAIL: getsockopt(%s, IPPROTO_IP, %s)", socktype, optstring);
  if (ret == 0 && (flags & 0x00000000))
    warnx("WARN: getsockopt(%s, IPPROTO_IP, %s) returned 0", socktype,
          optstring);
  if (uc != defaultv)
    errx(-1,
         "FAIL: getsockopt(%s, IPPROTO_IP, %s) default is "
         "%d not %d",
         socktype, optstring, uc, defaultv);
  uc = modifiedv;
  ret = setsockopt(sock, IPPROTO_IP, optname, &uc, sizeof(uc));
  if (ret == -1)
    err(-1, "FAIL: setsockopt(%s, IPPROTO_IP, %s)", socktype, optstring);
  if (ret == 0 && (flags & 0x00000000))
    warnx("WARN: setsockopt(%s, IPPROTO_IP, %s) returned 0", socktype,
          optstring);
  uc = fakev;
  socklen = sizeof(uc);
  ret = getsockopt(sock, IPPROTO_IP, optname, &uc, &socklen);
  if (ret < 0)
    err(-1, "FAIL: getsockopt(%s, IPPROTO_IP, %s)", socktype, optstring);
  if (ret == 0 && (flags & 0x00000000))
    warnx("WARN: getsockopt(%s, IPPROTO_IP, %s) returned 0", socktype,
          optstring);
  if (uc != modifiedv)
    errx(-1,
         "FAIL: getsockopt(%s, IPPROTO_IP, %s) set value is "
         "%d not %d",
         socktype, optstring, uc, modifiedv);
}


x86 assembly (clang, -O0):
<test_u_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x8,-0x34(%rbp)
mov    0x10(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    -0x40(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1060 <getsockopt@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    11c6 <test_u_char+0x76>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xe3f(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x44(%rbp)
jne    11f3 <test_u_char+0xa3>
mov    0x18(%rbp),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     11f3 <test_u_char+0xa3>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe37(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1222 <test_u_char+0xd2>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0xffffffff,%edi
lea    0xe38(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x10(%rbp),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    -0x40(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    126e <test_u_char+0x11e>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xe26(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x44(%rbp)
jne    129b <test_u_char+0x14b>
mov    0x18(%rbp),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     129b <test_u_char+0x14b>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe1e(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x8,-0x34(%rbp)
mov    0x10(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
lea    -0x40(%rbp),%rcx
lea    -0x34(%rbp),%r8
call   1060 <getsockopt@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12ec <test_u_char+0x19c>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xd19(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x44(%rbp)
jne    1319 <test_u_char+0x1c9>
mov    0x18(%rbp),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     1319 <test_u_char+0x1c9>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xd11(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1348 <test_u_char+0x1f8>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    $0xffffffff,%edi
lea    0xda1(%rip),%rsi
call   1040 <errx@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_u_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,0x10(%rsp)
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebp
mov    0x50(%rsp),%edi
mov    %r8,(%rsp)
movl   $0x8,0xc(%rsp)
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
mov    %ebp,%edx
call   1050 <getsockopt@plt>
test   %eax,%eax
jns    11a4 <test_u_char+0x64>
lea    0xe6c(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r14,%rdx
mov    %r13,%rcx
call   1060 <err@plt>
mov    (%rsp),%r8
cmp    %r12,%r8
je     11c7 <test_u_char+0x87>
lea    0xe71(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r14,%rdx
mov    %r13,%rcx
mov    %r12,%r9
call   1040 <errx@plt>
mov    %r14,%rbx
mov    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    0x2e0e(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rcx
mov    0x50(%rsp),%r12d
mov    %r12d,%edi
mov    %ebp,%edx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1211 <test_u_char+0xd1>
lea    0xe5e(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1060 <err@plt>
mov    %r15,(%rsp)
movl   $0x8,0xc(%rsp)
mov    (%r14),%esi
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
mov    %r12d,%edi
mov    %ebp,%edx
call   1050 <getsockopt@plt>
test   %eax,%eax
jns    124d <test_u_char+0x10d>
lea    0xdc3(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1060 <err@plt>
mov    (%rsp),%r8
mov    0x10(%rsp),%r9
cmp    %r9,%r8
je     1272 <test_u_char+0x132>
lea    0xe22(%rip),%rsi
mov    $0xffffffff,%edi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1040 <errx@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@IPPROTO_IP = global i32 0
@.str = [37 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s)\00"
@.str.1 = [48 x i8] c"WARN: getsockopt(%s, IPPROTO_IP, %s) returned 0\00"
@.str.2 = [58 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s) default is %d not %d\00"
@.str.3 = [37 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, %s)\00"
@.str.4 = [48 x i8] c"WARN: setsockopt(%s, IPPROTO_IP, %s) returned 0\00"
@.str.5 = [60 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s) set value is %d not %d\00"
define void @test_u_char(i32 %0, i8* %1, i64 %2, i64 %3, i64 %4, i8* %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i32
store i32 %0, i32* %9
store i8* %1, i8** %10
store i64 %2, i64* %11
store i64 %3, i64* %12
store i64 %4, i64* %13
store i8* %5, i8** %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%20 = load i64, i64* %13
store i64 %20, i64* %18
store i32 8, i32* %17
%21 = load i32, i32* %15
%22 = load i32, i32* @IPPROTO_IP
%23 = load i32, i32* %9
%24 = call i32 @getsockopt(i32 %21, i32 %22, i32 %23, i64* %18, i32* %17)
store i32 %24, i32* %19
%25 = load i32, i32* %19
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %8
%28 = load i8*, i8** %14
%29 = load i8*, i8** %10
%30 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
br label %31
31: ; preds = %27, %8
%32 = load i32, i32* %19
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %16
%36 = and i32 %35, 0
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i8*, i8** %14
%40 = load i8*, i8** %10
%41 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %40)
br label %42
42: ; preds = %38, %34, %31
%43 = load i64, i64* %18
%44 = load i64, i64* %11
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i8*, i8** %14
%48 = load i8*, i8** %10
%49 = load i64, i64* %18
%50 = load i64, i64* %11
%51 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %48, i64 %49, i64 %50)
br label %52
52: ; preds = %46, %42
%53 = load i64, i64* %12
store i64 %53, i64* %18
%54 = load i32, i32* %15
%55 = load i32, i32* @IPPROTO_IP
%56 = load i32, i32* %9
%57 = call i32 @setsockopt(i32 %54, i32 %55, i32 %56, i64* %18, i32 8)
store i32 %57, i32* %19
%58 = load i32, i32* %19
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %52
%61 = load i8*, i8** %14
%62 = load i8*, i8** %10
%63 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %62)
br label %64
64: ; preds = %60, %52
%65 = load i32, i32* %19
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %64
%68 = load i32, i32* %16
%69 = and i32 %68, 0
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i8*, i8** %14
%73 = load i8*, i8** %10
%74 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %72, i8* %73)
br label %75
75: ; preds = %71, %67, %64
%76 = load i64, i64* %13
store i64 %76, i64* %18
store i32 8, i32* %17
%77 = load i32, i32* %15
%78 = load i32, i32* @IPPROTO_IP
%79 = load i32, i32* %9
%80 = call i32 @getsockopt(i32 %77, i32 %78, i32 %79, i64* %18, i32* %17)
store i32 %80, i32* %19
%81 = load i32, i32* %19
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %75
%84 = load i8*, i8** %14
%85 = load i8*, i8** %10
%86 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %84, i8* %85)
br label %87
87: ; preds = %83, %75
%88 = load i32, i32* %19
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %98
90: ; preds = %87
%91 = load i32, i32* %16
%92 = and i32 %91, 0
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %90
%95 = load i8*, i8** %14
%96 = load i8*, i8** %10
%97 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %95, i8* %96)
br label %98
98: ; preds = %94, %90, %87
%99 = load i64, i64* %18
%100 = load i64, i64* %12
%101 = icmp ne i64 %99, %100
br i1 %101, label %102, label %108
102: ; preds = %98
%103 = load i8*, i8** %14
%104 = load i8*, i8** %10
%105 = load i64, i64* %18
%106 = load i64, i64* %12
%107 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %103, i8* %104, i64 %105, i64 %106)
br label %108
108: ; preds = %102, %98
ret void
}

LLVM IR (-O2):
@IPPROTO_IP = global i32 0
@.str = [37 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s)\00"
@.str.2 = [58 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s) default is %d not %d\00"
@.str.3 = [37 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, %s)\00"
@.str.5 = [60 x i8] c"FAIL: getsockopt(%s, IPPROTO_IP, %s) set value is %d not %d\00"
define void @test_u_char(i32 %0, i8* %1, i64 %2, i64 %3, i64 %4, i8* %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i64
%11 = bitcast i32* %9 to i8*
%12 = bitcast i64* %10 to i8*
store i64 %4, i64* %10
store i32 8, i32* %9
%13 = load i32, i32* @IPPROTO_IP
%14 = call i32 @getsockopt(i32 %6, i32 %13, i32 %0, i64* %10, i32* %9)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %1)
br label %18
18: ; preds = %16, %8
%19 = load i64, i64* %10
%20 = icmp eq i64 %19, %2
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %1, i64 %19, i64 %2)
br label %23
23: ; preds = %21, %18
store i64 %3, i64* %10
%24 = load i32, i32* @IPPROTO_IP
%25 = call i32 @setsockopt(i32 %6, i32 %24, i32 %0, i64* %10, i32 8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %1)
br label %29
29: ; preds = %27, %23
store i64 %4, i64* %10
store i32 8, i32* %9
%30 = load i32, i32* @IPPROTO_IP
%31 = call i32 @getsockopt(i32 %6, i32 %30, i32 %0, i64* %10, i32* %9)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @err(i32 -1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %1)
br label %35
35: ; preds = %33, %29
%36 = load i64, i64* %10
%37 = icmp eq i64 %36, %3
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i8* %5, i8* %1, i64 %36, i64 %3)
br label %40
40: ; preds = %38, %35
ret void
}