#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int osd_blank(char *path, int cmd) {
  int fd;
  char bcmd[16];
  fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
  if (fd >= 0) {
    sprintf(bcmd, "%d", cmd);
    write(fd, bcmd, strlen(bcmd));
    close(fd);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<osd_blank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
or     (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11e1 <osd_blank+0x91>
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe5d(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <osd_blank+0x98>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osd_blank>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rcx
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %esi,%ebp
mov    0x2e7d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
test   %eax,%eax
js     11ba <osd_blank+0x6a>
mov    %eax,%ebx
lea    0xe72(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11bf <osd_blank+0x6f>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @osd_blank(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [16 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_RDWR
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %8, i32 %13, i32 420)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %6
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
store i32 0, i32* %3
br label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %29
29: ; preds = %28, %17
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@.str = [3 x i8] c"%d\00"
define i32 @osd_blank(i8* nocapture %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 @open(i8* %0, i32 %9, i32 420)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @write(i32 %10, i8* %4, i32 %14)
%16 = call i32 @close(i32 %10)
br label %17
17: ; preds = %2, %12
%18 = phi i32 [ 0, %12 ], [ -1, %2 ]
ret i32 %18
}