#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
void trigger_fw(const char *fw_name, const char *sys_path) {
  int fd;
  fd = open(sys_path, O_WRONLY);
  if (fd < 0)
    die("open failed: %s\n", strerror(errno));
  if (write(fd, fw_name, strlen(fw_name)) != strlen(fw_name))
    exit(EXIT_FAILURE);
  close(fd);
}


x86 assembly (clang, -O0):
<trigger_fw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bb <trigger_fw+0x4b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
call   1070 <die@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     120c <trigger_fw+0x9c>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trigger_fw>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
mov    0x2e47(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1060 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11ae <trigger_fw+0x3e>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
call   1070 <die@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jne    11e0 <trigger_fw+0x70>
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [17 x i8] c"open failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @trigger_fw(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %2
%16 = load i32, i32* %5
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
%20 = call i64 @write(i32 %16, i8* %17, i64 %19)
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = icmp ne i64 %20, %22
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %15
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [17 x i8] c"open failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @trigger_fw(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* %1, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %2
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = tail call i64 @write(i32 %4, i8* %0, i64 %11)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = icmp eq i64 %12, %13
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = tail call i32 @close(i32 %4)
ret void
}