#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CLOEXEC;
int O_RDWR;
int /*<<< orphan*/ close(int);
int create(int);
int /*<<< orphan*/ destroy(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int open(char const *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  const char *path = "/dev/uhid";
  int ret;
  printf("Open uhid-cdev %s\n", path);
  fd = open(path, O_RDWR | O_CLOEXEC);
  if (fd < 0) {
    fprintf(stderr, "Cannot open uhid-cdev %s: %m\n", path);
    return EXIT_FAILURE;
  }
  printf("Create uhid device\n");
  ret = create(fd);
  if (ret != 0) {
    close(fd);
    return EXIT_FAILURE;
  }
  printf("Destroy uhid device\n");
  destroy(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <main+0x85>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <main+0xe3>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <create@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1221 <main+0xc1>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <main+0xe3>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <destroy@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe92(%rip),%rdi
lea    0xe81(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e58(%rip),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     11d0 <main+0x60>
mov    %eax,%ebx
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <create@plt>
test   %eax,%eax
je     11f5 <main+0x85>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x2e02(%rip),%rax
jmp    120f <main+0x9f>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
lea    0xe19(%rip),%rdx
call   1080 <fprintf@plt>
mov    0x2ddd(%rip),%rax
jmp    120f <main+0x9f>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <destroy@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/uhid\00"
@.str.1 = [19 x i8] c"Open uhid-cdev %s\0A\00"
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Cannot open uhid-cdev %s: %m\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [20 x i8] c"Create uhid device\0A\00"
@.str.4 = [21 x i8] c"Destroy uhid device\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %7
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CLOEXEC
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %11, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %7
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %38
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %6
%26 = call i32 @create(i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
store i32 %32, i32* %3
br label %38
33: ; preds = %23
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* %6
%36 = call i32 @destroy(i32 %35)
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %3
br label %38
38: ; preds = %33, %29, %18
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/uhid\00"
@.str.1 = [19 x i8] c"Open uhid-cdev %s\0A\00"
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Cannot open uhid-cdev %s: %m\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"Create uhid device\00"
@str.5 = [20 x i8] c"Destroy uhid device\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CLOEXEC
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %21
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @create(i32 %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i32 @close(i32 %7)
br label %21
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%20 = tail call i32 @destroy(i32 %7)
br label %21
21: ; preds = %18, %16, %9
%22 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_FAILURE, %16 ], [ @EXIT_SUCCESS, %18 ]
%23 = load i32, i32* %22
ret i32 %23
}