#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 fileaccess {
  int dummy;
};

/* Variables and functions */
struct fileaccess *sysfs_file_open(int, char *, char const *);
struct fileaccess *battery_n810_attr_open(int flags, const char *name) {
  struct fileaccess *fd;
  fd = sysfs_file_open(flags, "/devices/platform/n810bm/%s", name);
  if (fd)
    return fd;
  fd = sysfs_file_open(flags, "/devices/platform/tahvo/tahvo-n810bm/%s", name);
  if (fd)
    return fd;
  fd = sysfs_file_open(flags, "/devices/platform/retu/retu-n810bm/%s", name);
  if (fd)
    return fd;
  return NULL;
}


x86 assembly (clang, -O0):
<battery_n810_attr_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xed3(%rip),%rsi
call   1030 <sysfs_file_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     114e <battery_n810_attr_open+0x3e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <battery_n810_attr_open+0xa4>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xec0(%rip),%rsi
call   1030 <sysfs_file_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117d <battery_n810_attr_open+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <battery_n810_attr_open+0xa4>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xeb9(%rip),%rsi
call   1030 <sysfs_file_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ac <battery_n810_attr_open+0x9c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <battery_n810_attr_open+0xa4>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<battery_n810_attr_open>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xee1(%rip),%rsi
mov    %rbx,%rdx
call   1030 <sysfs_file_open@plt>
test   %rax,%rax
jne    1142 <battery_n810_attr_open+0x32>
lea    0xee9(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <sysfs_file_open@plt>
test   %rax,%rax
je     1149 <battery_n810_attr_open+0x39>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xef4(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <sysfs_file_open@plt>

LLVM IR (-O0):
%struct.fileaccess = type { i32 }
@.str = [28 x i8] c"/devices/platform/n810bm/%s\00"
@.str.1 = [40 x i8] c"/devices/platform/tahvo/tahvo-n810bm/%s\00"
@.str.2 = [38 x i8] c"/devices/platform/retu/retu-n810bm/%s\00"
define %struct.fileaccess* @battery_n810_attr_open(i32 %0, i8* %1) {
%3 = alloca %struct.fileaccess*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.fileaccess*
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = load i8*, i8** %5
%9 = call %struct.fileaccess* @sysfs_file_open(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8)
store %struct.fileaccess* %9, %struct.fileaccess** %6
%10 = load %struct.fileaccess*, %struct.fileaccess** %6
%11 = icmp ne %struct.fileaccess* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load %struct.fileaccess*, %struct.fileaccess** %6
store %struct.fileaccess* %13, %struct.fileaccess** %3
br label %31
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i8*, i8** %5
%17 = call %struct.fileaccess* @sysfs_file_open(i32 %15, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store %struct.fileaccess* %17, %struct.fileaccess** %6
%18 = load %struct.fileaccess*, %struct.fileaccess** %6
%19 = icmp ne %struct.fileaccess* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load %struct.fileaccess*, %struct.fileaccess** %6
store %struct.fileaccess* %21, %struct.fileaccess** %3
br label %31
22: ; preds = %14
%23 = load i32, i32* %4
%24 = load i8*, i8** %5
%25 = call %struct.fileaccess* @sysfs_file_open(i32 %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store %struct.fileaccess* %25, %struct.fileaccess** %6
%26 = load %struct.fileaccess*, %struct.fileaccess** %6
%27 = icmp ne %struct.fileaccess* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load %struct.fileaccess*, %struct.fileaccess** %6
store %struct.fileaccess* %29, %struct.fileaccess** %3
br label %31
30: ; preds = %22
store %struct.fileaccess* null, %struct.fileaccess** %3
br label %31
31: ; preds = %30, %28, %20, %12
%32 = load %struct.fileaccess*, %struct.fileaccess** %3
ret %struct.fileaccess* %32
}

LLVM IR (-O2):
%struct.fileaccess = type { i32 }
@.str = [28 x i8] c"/devices/platform/n810bm/%s\00"
@.str.1 = [40 x i8] c"/devices/platform/tahvo/tahvo-n810bm/%s\00"
@.str.2 = [38 x i8] c"/devices/platform/retu/retu-n810bm/%s\00"
define %struct.fileaccess* @battery_n810_attr_open(i32 %0, i8* %1) {
%3 = tail call %struct.fileaccess* @sysfs_file_open(i32 %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = icmp eq %struct.fileaccess* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call %struct.fileaccess* @sysfs_file_open(i32 %0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = icmp eq %struct.fileaccess* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call %struct.fileaccess* @sysfs_file_open(i32 %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %5, %2
%11 = phi %struct.fileaccess* [ %3, %2 ], [ %6, %5 ], [ %9, %8 ]
ret %struct.fileaccess* %11
}