#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_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strncmp(char *, char *, int);
int _open(char *name) {
  char path[255];
  sprintf(path, "%s%s",
          strncmp(name, "/dev/", sizeof "/dev/" - 1) ? "/dev/" : "", name);
  return open(path, O_RDWR | O_NONBLOCK | O_NOCTTY, 0640);
}


x86 assembly (clang, -O0):
<_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    -0x118(%rbp),%rdi
mov    %rax,%rcx
lea    0xe97(%rip),%rdx
lea    0xe8b(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe73(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
or     (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1040 <open@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_open>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
lea    0xec1(%rip),%r14
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0xeaf(%rip),%rdx
cmovne %r14,%rdx
lea    0xe9a(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rcx
call   1050 <sprintf@plt>
mov    0x2e6d(%rip),%rax
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e43(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a0,%edx
call   1040 <open@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [1 x i8] zeroinitializer
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
define i32 @_open(i8* %0) {
%2 = alloca i8*
%3 = alloca [255 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %2
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = icmp ne i64 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%10 = load i8*, i8** %2
%11 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %13, %14
%16 = load i32, i32* @O_NOCTTY
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %12, i32 %17, i32 416)
ret i32 %18
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [1 x i8] zeroinitializer
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@O_NOCTTY = global i32 0
define i32 @_open(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%7 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %0)
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NONBLOCK
%10 = or i32 %9, %8
%11 = load i32, i32* @O_NOCTTY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %3, i32 %12, i32 416)
ret i32 %13
}