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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ name_to_dev_t(char const *);
int open(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int, int, unsigned long long);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int resume(const char *resume_file, unsigned long long resume_offset) {
  dev_t resume_device;
  int powerfd = -1;
  char device_string[64];
  int len;
  resume_device = name_to_dev_t(resume_file);
  if (major(resume_device) == 0) {
    fprintf(stderr, "Invalid resume device: %s\n", resume_file);
    goto failure;
  }
  if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0)
    goto fail_r;
  len = snprintf(device_string, sizeof device_string, "%u:%u:%llu",
                 major(resume_device), minor(resume_device), resume_offset);
  if (len >= sizeof device_string)
    goto fail_r;
  ((void)0);
  if (write(powerfd, device_string, len) != len)
    goto fail_r;
failure:
  if (powerfd >= 0)
    close(powerfd);
  ((void)0);
  return -1;
fail_r:
  fprintf(stderr, "Cannot write /sys/power/resume "
                  "(no software suspend kernel support?)\n");
  goto failure;
}


x86 assembly (clang, -O0):
<resume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <name_to_dev_t@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <major@plt>
cmp    $0x0,%eax
jne    11d4 <resume+0x54>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    126c <resume+0xec>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11fa <resume+0x7a>
jmp    1289 <resume+0x109>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <major@plt>
mov    %eax,-0x68(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <minor@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%ecx
mov    %eax,%r8d
mov    -0x10(%rbp),%r9
mov    $0x40,%esi
lea    0xdfe(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x64(%rbp)
movslq -0x64(%rbp),%rax
cmp    $0x40,%rax
jb     124a <resume+0xca>
jmp    1289 <resume+0x109>
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <write@plt>
cmp    -0x64(%rbp),%eax
je     1267 <resume+0xe7>
jmp    1289 <resume+0x109>
jmp    126c <resume+0xec>
cmpl   $0x0,-0x18(%rbp)
jl     127e <resume+0xfe>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
add    $0x70,%rsp
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    126c <resume+0xec>

x86 assembly (clang, -O2):
<resume>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1080 <name_to_dev_t@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <major@plt>
test   %eax,%eax
je     122a <resume+0xaa>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1246 <resume+0xc6>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <major@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <minor@plt>
lea    0xe50(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %r15d,%ecx
mov    %eax,%r8d
mov    %r14,%r9
call   1050 <snprintf@plt>
cmp    $0x3f,%eax
ja     120a <resume+0x8a>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1221 <resume+0xa1>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    125d <resume+0xdd>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    125d <resume+0xdd>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Invalid resume device: %s\0A\00"
@.str.1 = [18 x i8] c"/sys/power/resume\00"
@O_WRONLY = global i32 0
@.str.2 = [11 x i8] c"%u:%u:%llu\00"
@.str.3 = [70 x i8] c"Cannot write /sys/power/resume (no software suspend kernel support?)\0A\00"
define i32 @resume(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 -1, i32* %6
%9 = load i8*, i8** %3
%10 = call i32 @name_to_dev_t(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = call i32 @major(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %44
18: ; preds = %2
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %51
23: ; preds = %18
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @major(i32 %25)
%27 = load i32, i32* %5
%28 = call i32 @minor(i32 %27)
%29 = load i64, i64* %4
%30 = call i32 @snprintf(i8* %24, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %28, i64 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = icmp uge i64 %32, 64
br i1 %33, label %34, label %35
34: ; preds = %23
br label %51
35: ; preds = %23
%36 = load i32, i32* %6
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%38 = load i32, i32* %8
%39 = call i32 @write(i32 %36, i8* %37, i32 %38)
%40 = load i32, i32* %8
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %35
br label %51
43: ; preds = %35
br label %44
44: ; preds = %51, %43, %14
%45 = load i32, i32* %6
%46 = icmp sge i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %47, %44
ret i32 -1
51: ; preds = %42, %34, %22
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
br label %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Invalid resume device: %s\0A\00"
@.str.1 = [18 x i8] c"/sys/power/resume\00"
@O_WRONLY = global i32 0
@.str.2 = [11 x i8] c"%u:%u:%llu\00"
@.str.3 = [70 x i8] c"Cannot write /sys/power/resume (no software suspend kernel support?)\0A\00"
define i32 @resume(i8* %0, i64 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @name_to_dev_t(i8* %0)
%6 = tail call i32 @major(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %31
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = tail call i32 @major(i32 %5)
%17 = tail call i32 @minor(i32 %5)
%18 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17, i64 %1)
%19 = icmp ugt i32 %18, 63
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = call i32 @write(i32 %13, i8* %4, i32 %18)
%22 = icmp eq i32 %21, %18
br i1 %22, label %29, label %23
23: ; preds = %15, %20
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
br label %29
26: ; preds = %11
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %20, %23
%30 = call i32 @close(i32 %13)
br label %31
31: ; preds = %26, %8, %29
ret i32 -1
}