#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 /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ assert(int);
scalar_t__ get_dev_no_by_path(char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int test() {
  int err = 0;
  int fd = -1;
  char *path = "/tmp/abc";
  printf("start test:\n");
  assert((fd = open(path, O_RDWR | O_CREAT, S_IRWXU)) > 0);
  printf("dev_no(path=%s)=%d\n", path, (int)get_dev_no_by_path(path));
  return err;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e75(%rip),%rax
or     (%rax),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_dev_no_by_path@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbx
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e74(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1060 <open@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1070 <get_dev_no_by_path@plt>
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/tmp/abc\00"
@.str.1 = [13 x i8] c"start test:\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [20 x i8] c"dev_no(path=%s)=%d\0A\00"
define i32 @test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
store i32 -1, i32* %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRWXU
%10 = call i32 @open(i8* %5, i32 %8, i32 %9)
store i32 %10, i32* %2
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i64 @get_dev_no_by_path(i8* %15)
%17 = trunc i64 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %17)
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [9 x i8] c"/tmp/abc\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [20 x i8] c"dev_no(path=%s)=%d\0A\00"
@str = [12 x i8] c"start test:\00"
define i32 @test() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IRWXU
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = icmp sgt i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i64 @get_dev_no_by_path(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = trunc i64 %10 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}