#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strncmp(char *, char *, int);
int isamdgpu(char *path) {
  char buffer[255], buf[10];
  int fd, res = -1;
  sprintf(buffer, "%s/name", path);
  fd = open(buffer, O_RDONLY);
  if (fd < 0)
    return -1;
  if (read(fd, buf, 10) > 0)
    res = strncmp(buf, "amdgpu", 6);
  close(fd);
  return res;
}


x86 assembly (clang, -O0):
<isamdgpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x124(%rbp)
ff ff ff
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0x0,-0x120(%rbp)
jge    11b4 <isamdgpu+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <isamdgpu+0xb7>
mov    -0x120(%rbp),%edi
lea    -0x11a(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    11f3 <isamdgpu+0xa3>
lea    -0x11a(%rbp),%rdi
lea    0xe25(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x124(%rbp)
mov    -0x120(%rbp),%edi
call   1040 <close@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isamdgpu>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rdx
lea    0xe9d(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b7 <isamdgpu+0x67>
mov    %eax,%ebx
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11be <isamdgpu+0x6e>
lea    0xe64(%rip),%rsi
lea    0x6(%rsp),%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %eax,%ebp
jmp    11c3 <isamdgpu+0x73>
mov    $0xffffffff,%ebp
jmp    11ca <isamdgpu+0x7a>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x118,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s/name\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"amdgpu\00"
define i32 @isamdgpu(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = alloca [10 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %7
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %29
17: ; preds = %1
%18 = load i32, i32* %6
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%20 = call i64 @read(i32 %18, i8* %19, i32 10)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%24 = call i32 @strncmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
store i32 %24, i32* %7
br label %25
25: ; preds = %22, %17
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
store i32 %28, i32* %2
br label %29
29: ; preds = %25, %16
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/name\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"amdgpu\00"
define i32 @isamdgpu(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %4, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = call i64 @read(i32 %8, i8* %5, i32 10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %14, %13 ], [ -1, %10 ]
%17 = call i32 @close(i32 %8)
br label %18
18: ; preds = %1, %15
%19 = phi i32 [ %16, %15 ], [ -1, %1 ]
ret i32 %19
}