#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 */
typedef int cl_uint;
typedef int /*<<< orphan*/ cl_platform_id;
typedef int /*<<< orphan*/ cl_int;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ CL_PLATFORM_VENDOR;
int /*<<< orphan*/ clGetPlatformIDs(int, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ clGetPlatformInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                                     int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ oclCheckStatus(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
cl_platform_id oclGetFirstPlatformFromVendor(const char *vendor) {
  cl_int status;
  cl_uint numPlatforms;
  cl_platform_id platforms[256];
  status = clGetPlatformIDs(256, platforms, &numPlatforms);
  oclCheckStatus(status, "clGetPlatformIDs failed.");
  int i;
  for (i = 0; i < numPlatforms; i++) {
    char buffer[128];
    status = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(buffer),
                               buffer, NULL);
    oclCheckStatus(status, "clGetPlatformInfo(CL_PLATFORM_VENDOR) failed.");
    if (strncmp(buffer, vendor, strlen(vendor)) == 0) {
      return platforms[i];
    }
  }
  fprintf(stderr, "No OpenCL platform available for vendor '%s'", vendor);
  exit(1);
}


x86 assembly (clang, -O0):
<oclGetFirstPlatformFromVendor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rsi
mov    $0x100,%edi
lea    -0x10(%rbp),%rdx
call   1050 <clGetPlatformIDs@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe5f(%rip),%rsi
call   1080 <oclCheckStatus@plt>
movl   $0x0,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    126f <oclGetFirstPlatformFromVendor+0xff>
movslq -0x414(%rbp),%rax
mov    -0x410(%rbp,%rax,4),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    -0x4a0(%rbp),%rcx
mov    $0x80,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <clGetPlatformInfo@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe20(%rip),%rsi
call   1080 <oclCheckStatus@plt>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4b0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4b0(%rbp),%rdi
mov    -0x4a8(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1256 <oclGetFirstPlatformFromVendor+0xe6>
movslq -0x414(%rbp),%rax
mov    -0x410(%rbp,%rax,4),%eax
add    $0x4b0,%rsp
pop    %rbp
ret
jmp    125b <oclGetFirstPlatformFromVendor+0xeb>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11b0 <oclGetFirstPlatformFromVendor+0x40>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc4(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<oclGetFirstPlatformFromVendor>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x490,%rsp
mov    %rdi,%r12
lea    0x90(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    $0x100,%edi
call   1050 <clGetPlatformIDs@plt>
lea    0xe5f(%rip),%rsi
mov    %eax,%edi
call   1080 <oclCheckStatus@plt>
cmpl   $0x0,0xc(%rsp)
jle    121d <oclGetFirstPlatformFromVendor+0xad>
xor    %ebx,%ebx
mov    0x2e18(%rip),%r13
lea    0x10(%rsp),%r14
lea    0xe55(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x90(%rsp,%rbx,4),%edi
mov    0x0(%r13),%esi
mov    $0x80,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1060 <clGetPlatformInfo@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1080 <oclCheckStatus@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     123f <oclGetFirstPlatformFromVendor+0xcf>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11d0 <oclGetFirstPlatformFromVendor+0x60>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    %r12,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x90(%rsp,%rbx,4),%eax
add    $0x490,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"clGetPlatformIDs failed.\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.1 = [46 x i8] c"clGetPlatformInfo(CL_PLATFORM_VENDOR) failed.\00"
@stderr = global i32 0
@.str.2 = [45 x i8] c"No OpenCL platform available for vendor '%s'\00"
define i32 @oclGetFirstPlatformFromVendor(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i32]
%6 = alloca i32
%7 = alloca [128 x i8]
store i8* %0, i8** %2
%8 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 0
%9 = call i32 @clGetPlatformIDs(i32 256, i32* %8, i32* %4)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @oclCheckStatus(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %12
12: ; preds = %38, %1
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = load i32, i32* @CL_PLATFORM_VENDOR
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%23 = call i32 @clGetPlatformInfo(i32 %20, i32 %21, i32 128, i8* %22, i32* null)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @oclCheckStatus(i32 %24, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %2
%28 = load i8*, i8** %2
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @strncmp(i8* %26, i8* %27, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %16
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %34
%36 = load i32, i32* %35
ret i32 %36
37: ; preds = %16
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %12
41: ; preds = %12
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %2
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [25 x i8] c"clGetPlatformIDs failed.\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.1 = [46 x i8] c"clGetPlatformInfo(CL_PLATFORM_VENDOR) failed.\00"
@stderr = global i32 0
@.str.2 = [45 x i8] c"No OpenCL platform available for vendor '%s'\00"
define i32 @oclGetFirstPlatformFromVendor(i8* %0) {
%2 = alloca i32
%3 = alloca [256 x i32]
%4 = alloca [128 x i8]
%5 = bitcast i32* %2 to i8*
%6 = bitcast [256 x i32]* %3 to i8*
%7 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 0
%8 = call i32 @clGetPlatformIDs(i32 256, i32* %7, i32* %2)
%9 = call i32 @oclCheckStatus(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
br label %14
14: ; preds = %12, %24
%15 = phi i64 [ 0, %12 ], [ %25, %24 ]
%16 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* @CL_PLATFORM_VENDOR
%19 = call i32 @clGetPlatformInfo(i32 %17, i32 %18, i32 128, i8* %13, i32* null)
%20 = call i32 @oclCheckStatus(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @strlen(i8* %0)
%22 = call i64 @strncmp(i8* %13, i8* %0, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %14
%25 = add nuw nsw i64 %15, 1
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %14, label %29
29: ; preds = %24, %1
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %14
%34 = and i64 %15, 4294967295
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 %34
%36 = load i32, i32* %35
ret i32 %36
}