#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*/ O_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd, ret;
  fd = open("/dev/char2", O_RDWR);
  if (fd < 0) {
    perror("open /dev/char2");
    exit(1);
  }
  ret = ioctl(fd, _IO('Z', 1));
  if (ret == 0)
    printf("Reset OK\n");
  else
    printf("Reset Error\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a7 <main+0x47>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x5a,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e4 <main+0x84>
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0x90>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    1190 <main+0x30>
lea    0xe7f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
mov    $0x5a,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %eax,%eax
lea    0xe69(%rip),%rax
lea    0xe56(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/char2\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/char2\00"
@.str.2 = [10 x i8] c"Reset OK\0A\00"
@.str.3 = [13 x i8] c"Reset Error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @_IO(i8 signext 90, i32 1)
%14 = call i32 @ioctl(i32 %12, i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %21
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/char2\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/char2\00"
@str = [12 x i8] c"Reset Error\00"
@str.4 = [9 x i8] c"Reset OK\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @_IO(i8 signext 90, i32 1)
%9 = tail call i32 @ioctl(i32 %2, i32 %8)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0)
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = tail call i32 @exit(i32 0)
unreachable
}