#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 IntOrError(int, char **, int);
int Os9Open(char *, int, int *);
int /*<<< orphan*/ RestoreLastChar(char *, char);
char SetHiBitOfLastChar(char *);
int atoi(char *);
int picolCommand9Open(int argc, char **argv, void *pd) {
  char *path = argv[1];
  char final = SetHiBitOfLastChar(path);
  int mode = atoi(argv[2]);
  int fd = 0;
  int e = Os9Open(path, mode, &fd);
  RestoreLastChar(path, final);
  return IntOrError(e, argv, fd);
}


x86 assembly (clang, -O0):
<picolCommand9Open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <SetHiBitOfLastChar@plt>
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
lea    -0x2c(%rbp),%rdx
call   1050 <Os9Open@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x21(%rbp),%esi
call   1070 <RestoreLastChar@plt>
mov    -0x30(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <IntOrError@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<picolCommand9Open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <SetHiBitOfLastChar@plt>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
call   1060 <atoi@plt>
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <Os9Open@plt>
mov    %eax,%ebp
movsbl %r15b,%esi
mov    %rbx,%rdi
call   1070 <RestoreLastChar@plt>
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <IntOrError@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @picolCommand9Open(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call signext i8 @SetHiBitOfLastChar(i8* %15)
store i8 %16, i8* %8
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %9
store i32 0, i32* %10
%21 = load i8*, i8** %7
%22 = load i32, i32* %9
%23 = call i32 @Os9Open(i8* %21, i32 %22, i32* %10)
store i32 %23, i32* %11
%24 = load i8*, i8** %7
%25 = load i8, i8* %8
%26 = call i32 @RestoreLastChar(i8* %24, i8 signext %25)
%27 = load i32, i32* %11
%28 = load i8**, i8*** %5
%29 = load i32, i32* %10
%30 = call i32 @IntOrError(i32 %27, i8** %28, i32 %29)
ret i32 %30
}

LLVM IR (-O2):
define i32 @picolCommand9Open(i32 %0, i8** %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call signext i8 @SetHiBitOfLastChar(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = call i32 @Os9Open(i8* %6, i32 %10, i32* %4)
%13 = call i32 @RestoreLastChar(i8* %6, i8 signext %7)
%14 = load i32, i32* %4
%15 = call i32 @IntOrError(i32 %12, i8** %1, i32 %14)
ret i32 %15
}