#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 */
char *om_sysfs_path(char const *);
char *om_sysfs_readfile(char const *);
scalar_t__ om_sysfs_writefile(char const *, char const *);
const char *om_sysfs_swap(const char *name, const char *val) {
  const char *path = om_sysfs_path(name);
  const char *res = NULL;
  if (path == NULL)
    return NULL;
  res = om_sysfs_readfile(path);
  if (om_sysfs_writefile(path, val) != 0)
    return NULL;
  return res;
}


x86 assembly (clang, -O0):
<om_sysfs_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <om_sysfs_path@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116d <om_sysfs_swap+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <om_sysfs_swap+0x76>
mov    -0x20(%rbp),%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <om_sysfs_writefile@plt>
cmp    $0x0,%rax
je     119e <om_sysfs_swap+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <om_sysfs_swap+0x76>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<om_sysfs_swap>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1040 <om_sysfs_path@plt>
test   %rax,%rax
je     1169 <om_sysfs_swap+0x39>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <om_sysfs_readfile@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <om_sysfs_writefile@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmove  %r15,%rax
jmp    116b <om_sysfs_swap+0x3b>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @om_sysfs_swap(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i8* @om_sysfs_path(i8* %8)
store i8* %9, i8** %6
store i8* null, i8** %7
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %23
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i8* @om_sysfs_readfile(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = call i64 @om_sysfs_writefile(i8* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i8* null, i8** %3
br label %23
21: ; preds = %13
%22 = load i8*, i8** %7
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %20, %12
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
define i8* @om_sysfs_swap(i8* %0, i8* %1) {
%3 = tail call i8* @om_sysfs_path(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i8* @om_sysfs_readfile(i8* %3)
%7 = tail call i64 @om_sysfs_writefile(i8* %3, i8* %1)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8* %6, i8* null
br label %10
10: ; preds = %5, %2
%11 = phi i8* [ null, %2 ], [ %9, %5 ]
ret i8* %11
}