#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*/ buf_too_big;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOBUFS;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ powercap_sysfs_control_type_exists(char *);
void test_bad_control_type_exists(void) {
  char buf_too_big[4096 + 1];
  size_t i;
  errno = 0;
  assert(powercap_sysfs_control_type_exists(NULL) == -EINVAL);
  assert(errno == EINVAL);
  errno = 0;
  assert(powercap_sysfs_control_type_exists("") == -EINVAL);
  assert(errno == EINVAL);
  errno = 0;
  assert(powercap_sysfs_control_type_exists(".") == -EINVAL);
  assert(errno == EINVAL);
  errno = 0;
  assert(powercap_sysfs_control_type_exists("/") == -EINVAL);
  assert(errno == EINVAL);
  for (i = 0; i < sizeof(buf_too_big); i++) {
    buf_too_big[i] = 'a';
  }
  buf_too_big[i - 1] = '\0';
  errno = 0;
  assert(powercap_sysfs_control_type_exists(buf_too_big) == -ENOBUFS);
  assert(errno == ENOBUFS);
  errno = 0;
  assert(powercap_sysfs_control_type_exists("foo") == -ENOSYS);
  assert(errno == ENOSYS);
}


x86 assembly (clang, -O0):
<test_bad_control_type_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    0x2e9e(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2e7e(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e4f(%rip),%rax
movl   $0x0,(%rax)
lea    0xe73(%rip),%rdi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2e2c(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dfd(%rip),%rax
movl   $0x0,(%rax)
lea    0xe20(%rip),%rdi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2dda(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2dab(%rip),%rax
movl   $0x0,(%rax)
lea    0xdd0(%rip),%rdi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2d88(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x1018(%rbp)
cmpq   $0x1001,-0x1018(%rbp)
jae    12b2 <test_bad_control_type_exists+0x192>
mov    -0x1018(%rbp),%rax
movb   $0x61,-0x1010(%rbp,%rax,1)
61
mov    -0x1018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1018(%rbp)
jmp    127b <test_bad_control_type_exists+0x15b>
mov    -0x1018(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
mov    0x2d04(%rip),%rax
movl   $0x0,(%rax)
lea    -0x1010(%rbp),%rdi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2d11(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2cb2(%rip),%rax
movl   $0x0,(%rax)
lea    0xcd9(%rip),%rdi
call   1030 <powercap_sysfs_control_type_exists@plt>
xor    %ecx,%ecx
mov    0x2ca7(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2c7f(%rip),%rax
mov    (%rax),%eax
mov    0x2c86(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bad_control_type_exists>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    0x2e8f(%rip),%r14
movl   $0x0,(%r14)
xor    %edi,%edi
call   1040 <powercap_sysfs_control_type_exists@plt>
mov    0x2e72(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x0,(%r14)
lea    0xe80(%rip),%rdi
call   1040 <powercap_sysfs_control_type_exists@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x0,(%r14)
lea    0xe4f(%rip),%rdi
call   1040 <powercap_sysfs_control_type_exists@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x0,(%r14)
lea    0xe21(%rip),%rdi
call   1040 <powercap_sysfs_control_type_exists@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    %rsp,%rbx
mov    $0x1000,%edx
mov    %rbx,%rdi
mov    $0x61,%esi
call   1030 <memset@plt>
movb   $0x0,0x1000(%rsp)
movl   $0x0,(%r14)
mov    %rbx,%rdi
call   1040 <powercap_sysfs_control_type_exists@plt>
mov    0x2dc2(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
movl   $0x0,(%r14)
lea    0xda3(%rip),%rdi
call   1040 <powercap_sysfs_control_type_exists@plt>
mov    0x2d73(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    (%r14),%eax
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
@EINVAL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"/\00"
@ENOBUFS = global i32 0
@.str.3 = [4 x i8] c"foo\00"
@ENOSYS = global i32 0
define void @test_bad_control_type_exists() {
%1 = alloca [4097 x i8]
%2 = alloca i64
store i32 0, i32* @errno
%3 = call i32 @powercap_sysfs_control_type_exists(i8* null)
%4 = load i32, i32* @EINVAL
%5 = sub nsw i32 0, %4
%6 = icmp eq i32 %3, %5
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* @errno
%10 = load i32, i32* @EINVAL
%11 = icmp eq i32 %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
store i32 0, i32* @errno
%14 = call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
%17 = icmp eq i32 %14, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @errno
%21 = load i32, i32* @EINVAL
%22 = icmp eq i32 %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
store i32 0, i32* @errno
%25 = call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EINVAL
%27 = sub nsw i32 0, %26
%28 = icmp eq i32 %25, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @errno
%32 = load i32, i32* @EINVAL
%33 = icmp eq i32 %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
store i32 0, i32* @errno
%36 = call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @EINVAL
%38 = sub nsw i32 0, %37
%39 = icmp eq i32 %36, %38
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i32, i32* @errno
%43 = load i32, i32* @EINVAL
%44 = icmp eq i32 %42, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
store i64 0, i64* %2
br label %47
47: ; preds = %53, %0
%48 = load i64, i64* %2
%49 = icmp ult i64 %48, 4097
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i64, i64* %2
%52 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 %51
store i8 97, i8* %52
br label %53
53: ; preds = %50
%54 = load i64, i64* %2
%55 = add i64 %54, 1
store i64 %55, i64* %2
br label %47
56: ; preds = %47
%57 = load i64, i64* %2
%58 = sub i64 %57, 1
%59 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 %58
store i8 0, i8* %59
store i32 0, i32* @errno
%60 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 0
%61 = call i32 @powercap_sysfs_control_type_exists(i8* %60)
%62 = load i32, i32* @ENOBUFS
%63 = sub nsw i32 0, %62
%64 = icmp eq i32 %61, %63
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load i32, i32* @errno
%68 = load i32, i32* @ENOBUFS
%69 = icmp eq i32 %67, %68
%70 = zext i1 %69 to i32
%71 = call i32 @assert(i32 %70)
store i32 0, i32* @errno
%72 = call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32, i32* @ENOSYS
%74 = sub nsw i32 0, %73
%75 = icmp eq i32 %72, %74
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
%78 = load i32, i32* @errno
%79 = load i32, i32* @ENOSYS
%80 = icmp eq i32 %78, %79
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@EINVAL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"/\00"
@ENOBUFS = global i32 0
@.str.3 = [4 x i8] c"foo\00"
@ENOSYS = global i32 0
define void @test_bad_control_type_exists() {
%1 = alloca [4097 x i8]
%2 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 0
store i32 0, i32* @errno
%4 = tail call i32 @powercap_sysfs_control_type_exists(i8* null)
%5 = load i32, i32* @EINVAL
%6 = sub nsw i32 0, %5
%7 = icmp eq i32 %4, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* @errno
%11 = load i32, i32* @EINVAL
%12 = icmp eq i32 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
store i32 0, i32* @errno
%15 = tail call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EINVAL
%17 = sub nsw i32 0, %16
%18 = icmp eq i32 %15, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i32, i32* @errno
%22 = load i32, i32* @EINVAL
%23 = icmp eq i32 %21, %22
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
store i32 0, i32* @errno
%26 = tail call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EINVAL
%28 = sub nsw i32 0, %27
%29 = icmp eq i32 %26, %28
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = load i32, i32* @errno
%33 = load i32, i32* @EINVAL
%34 = icmp eq i32 %32, %33
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
store i32 0, i32* @errno
%37 = tail call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EINVAL
%39 = sub nsw i32 0, %38
%40 = icmp eq i32 %37, %39
%41 = zext i1 %40 to i32
%42 = tail call i32 @assert(i32 %41)
%43 = load i32, i32* @errno
%44 = load i32, i32* @EINVAL
%45 = icmp eq i32 %43, %44
%46 = zext i1 %45 to i32
%47 = tail call i32 @assert(i32 %46)
%48 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 4096
store i8 0, i8* %48
store i32 0, i32* @errno
%49 = call i32 @powercap_sysfs_control_type_exists(i8* %3)
%50 = load i32, i32* @ENOBUFS
%51 = sub nsw i32 0, %50
%52 = icmp eq i32 %49, %51
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load i32, i32* @errno
%56 = load i32, i32* @ENOBUFS
%57 = icmp eq i32 %55, %56
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
store i32 0, i32* @errno
%60 = call i32 @powercap_sysfs_control_type_exists(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* @ENOSYS
%62 = sub nsw i32 0, %61
%63 = icmp eq i32 %60, %62
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = load i32, i32* @errno
%67 = load i32, i32* @ENOSYS
%68 = icmp eq i32 %66, %67
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
ret void
}