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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, long);
scalar_t__ write_device_file(size_t, char const *, char *, int);
int write_device_file_long(size_t led_number, const char *device_file,
                           long value) {
  int err;
  char value_str[22];
  snprintf(value_str, sizeof(value_str), "%ld", value);
  if ((err = write_device_file(led_number, device_file, value_str,
                               sizeof(value_str)) < 0)) {
    return err;
  }
  return 1;
}


x86 assembly (clang, -O0):
<write_device_file_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x16,%esi
lea    0xeb8(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x16,%ecx
call   1040 <write_device_file@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x24(%rbp)
test   $0x1,%al
jne    1182 <write_device_file_long+0x62>
jmp    118d <write_device_file_long+0x6d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <write_device_file_long+0x74>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_device_file_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rcx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec7(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x16,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x16,%ecx
call   1040 <write_device_file@plt>
mov    %rax,%rcx
shr    $0x3f,%rcx
test   %rax,%rax
mov    $0x1,%eax
cmovs  %ecx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @write_device_file_long(i64 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [22 x i8]
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = getelementptr inbounds [22 x i8], [22 x i8]* %9, i64 0, i64 0
%11 = load i64, i64* %7
%12 = call i32 @snprintf(i8* %10, i32 22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = load i64, i64* %5
%14 = load i8*, i8** %6
%15 = getelementptr inbounds [22 x i8], [22 x i8]* %9, i64 0, i64 0
%16 = call i64 @write_device_file(i64 %13, i8* %14, i8* %15, i32 22)
%17 = icmp slt i64 %16, 0
%18 = zext i1 %17 to i32
store i32 %18, i32* %8
br i1 %17, label %19, label %21
19: ; preds = %3
%20 = load i32, i32* %8
store i32 %20, i32* %4
br label %22
21: ; preds = %3
store i32 1, i32* %4
br label %22
22: ; preds = %21, %19
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @write_device_file_long(i64 %0, i8* %1, i64 %2) {
%4 = alloca [22 x i8]
%5 = getelementptr inbounds [22 x i8], [22 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %2)
%7 = call i64 @write_device_file(i64 %0, i8* %1, i8* %5, i32 22)
%8 = icmp slt i64 %7, 0
%9 = lshr i64 %7, 63
%10 = trunc i64 %9 to i32
%11 = select i1 %8, i32 %10, i32 1
ret i32 %11
}