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

/* Variables and functions */
int /*<<< orphan*/ RTC_VL_CLR;
int /*<<< orphan*/ RTC_VL_READ;
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int test_low_voltage(int fd) {
  int ret;
  int state;
  printf("==== voltage low operatoin ====\n");
  ret = ioctl(fd, RTC_VL_READ, &state);
  if (ret) {
    printf("read voltage low failed: %s\n", strerror(errno));
    return ret;
  }
  printf("\tvoltage low: %s\n", state ? "Low" : "Normal");
  if (state) {
    printf("\tclear voltage low flag\n");
    ret = ioctl(fd, RTC_VL_CLR, NULL);
    if (ret) {
      printf("clear voltage low failed: %s\n", strerror(errno));
      return ret;
    }
    printf("\tOK.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_low_voltage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1195 <test_low_voltage+0x65>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <test_low_voltage+0x104>
mov    -0x10(%rbp),%ecx
lea    0xeb5(%rip),%rsi
lea    0xeaa(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
je     122d <test_low_voltage+0xfd>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121f <test_low_voltage+0xef>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1234 <test_low_voltage+0x104>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_low_voltage>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xf0c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
test   %eax,%eax
je     1194 <test_low_voltage+0x54>
mov    %eax,%ebx
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmpl   $0x0,0x4(%rsp)
lea    0xe93(%rip),%rax
lea    0xe88(%rip),%rsi
cmove  %rax,%rsi
lea    0xe6b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
je     118b <test_low_voltage+0x4b>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %eax,%eax
je     120b <test_low_voltage+0xcb>
mov    %eax,%ebp
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe3d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebx
jmp    118b <test_low_voltage+0x4b>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
jmp    118b <test_low_voltage+0x4b>

LLVM IR (-O0):
@.str = [33 x i8] c"==== voltage low operatoin ====\0A\00"
@RTC_VL_READ = global i32 0
@.str.1 = [29 x i8] c"read voltage low failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [18 x i8] c"\09voltage low: %s\0A\00"
@.str.3 = [4 x i8] c"Low\00"
@.str.4 = [7 x i8] c"Normal\00"
@.str.5 = [25 x i8] c"\09clear voltage low flag\0A\00"
@RTC_VL_CLR = global i32 0
@.str.6 = [30 x i8] c"clear voltage low failed: %s\0A\00"
@.str.7 = [6 x i8] c"\09OK.\0A\00"
define i32 @test_low_voltage(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %3
%8 = load i32, i32* @RTC_VL_READ
%9 = call i32 @ioctl(i32 %7, i32 %8, i32* %5)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %40
17: ; preds = %1
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %17
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = load i32, i32* @RTC_VL_CLR
%29 = call i32 @ioctl(i32 %27, i32 %28, i32* null)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %25
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %40
37: ; preds = %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %37, %17
store i32 0, i32* %2
br label %40
40: ; preds = %39, %32, %12
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@RTC_VL_READ = global i32 0
@.str.1 = [29 x i8] c"read voltage low failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [18 x i8] c"\09voltage low: %s\0A\00"
@.str.3 = [4 x i8] c"Low\00"
@.str.4 = [7 x i8] c"Normal\00"
@RTC_VL_CLR = global i32 0
@.str.6 = [30 x i8] c"clear voltage low failed: %s\0A\00"
@str = [32 x i8] c"==== voltage low operatoin ====\00"
@str.8 = [24 x i8] c"\09clear voltage low flag\00"
@str.9 = [5 x i8] c"\09OK.\00"
define i32 @test_low_voltage(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @RTC_VL_READ
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %30
12: ; preds = %1
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%21 = load i32, i32* @RTC_VL_CLR
%22 = call i32 @ioctl(i32 %0, i32 %21, i32* null)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %26)
br label %30
28: ; preds = %19
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.9, i64 0, i64 0))
br label %30
30: ; preds = %12, %28, %24, %8
%31 = phi i32 [ %6, %8 ], [ %22, %24 ], [ 0, %28 ], [ 0, %12 ]
ret i32 %31
}