#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*/ package_reboot_device(char *);
int /*<<< orphan*/ printf(char *);
int write_buffer(int, char *, int /*<<< orphan*/ *);
int device_reboot(int tty) {
  char buffer[17];
  int res;
  printf("++ reset:\n");
  package_reboot_device(buffer);
  res = write_buffer(tty, buffer, NULL);
  if (res < 17) {
    printf("?? can't reboot device, package is too short\n");
    return res;
  }
  return 0;
}


x86 assembly (clang, -O0):
<device_reboot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <package_reboot_device@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <write_buffer@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x11,-0x24(%rbp)
jge    1184 <device_reboot+0x54>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <device_reboot+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_reboot>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <package_reboot_device@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <write_buffer@plt>
cmp    $0x10,%eax
jg     1174 <device_reboot+0x44>
mov    %eax,%ebp
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"++ reset:\0A\00"
@.str.1 = [46 x i8] c"?? can't reboot device, package is too short\0A\00"
define i32 @device_reboot(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [17 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%8 = call i32 @package_reboot_device(i8* %7)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%11 = call i32 @write_buffer(i32 %9, i8* %10, i32* null)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 17
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %5
store i32 %16, i32* %2
br label %18
17: ; preds = %1
store i32 0, i32* %2
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@str = [10 x i8] c"++ reset:\00"
@str.2 = [45 x i8] c"?? can't reboot device, package is too short\00"
define i32 @device_reboot(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%5 = call i32 @package_reboot_device(i8* %3)
%6 = call i32 @write_buffer(i32 %0, i8* %3, i32* null)
%7 = icmp slt i32 %6, 17
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.2, i64 0, i64 0))
br label %10
10: ; preds = %1, %8
%11 = phi i32 [ %6, %8 ], [ 0, %1 ]
ret i32 %11
}