#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 */
struct rdpmc_ctx {
  int dummy;
};
struct perf_event_attr {
  unsigned int config;
  int exclude_kernel;
  int /*<<< orphan*/ sample_type;
  int /*<<< orphan*/ size;
  int /*<<< orphan*/ type;
};

/* Variables and functions */
int /*<<< orphan*/ PERF_ATTR_SIZE_VER0;
int /*<<< orphan*/ PERF_SAMPLE_READ;
int /*<<< orphan*/ PERF_TYPE_HARDWARE;
int /*<<< orphan*/ PERF_TYPE_RAW;
int rdpmc_open_attr(struct perf_event_attr *, struct rdpmc_ctx *,
                    int /*<<< orphan*/ *);
int rdpmc_open(unsigned counter, struct rdpmc_ctx *ctx) {
  struct perf_event_attr attr = {
      .type = counter > 10 ? PERF_TYPE_RAW : PERF_TYPE_HARDWARE,
      .size = PERF_ATTR_SIZE_VER0,
      .config = counter,
      .sample_type = PERF_SAMPLE_READ,
      .exclude_kernel = 1,
  };
  return rdpmc_open_attr(&attr, ctx, NULL);
}


x86 assembly (clang, -O0):
<rdpmc_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0xa,-0x4(%rbp)
jbe    116b <rdpmc_open+0x5b>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    1177 <rdpmc_open+0x67>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <rdpmc_open_attr@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdpmc_open>:
sub    $0x18,%rsp
mov    %edi,(%rsp)
movl   $0x1,0x4(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
cmp    $0xb,%edi
jb     1147 <rdpmc_open+0x37>
mov    0x2ea3(%rip),%rax
jmp    114e <rdpmc_open+0x3e>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %rsp,%rdi
xor    %edx,%edx
call   1030 <rdpmc_open_attr@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.rdpmc_ctx = type { i32 }
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@PERF_SAMPLE_READ = global i32 0
@PERF_ATTR_SIZE_VER0 = global i32 0
@PERF_TYPE_RAW = global i32 0
@PERF_TYPE_HARDWARE = global i32 0
define i32 @rdpmc_open(i32 %0, %struct.rdpmc_ctx* %1) {
%3 = alloca i32
%4 = alloca %struct.rdpmc_ctx*
%5 = alloca %struct.perf_event_attr
store i32 %0, i32* %3
store %struct.rdpmc_ctx* %1, %struct.rdpmc_ctx** %4
%6 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 0
%7 = load i32, i32* %3
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 1
store i32 1, i32* %8
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 2
%10 = load i32, i32* @PERF_SAMPLE_READ
store i32 %10, i32* %9
%11 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 3
%12 = load i32, i32* @PERF_ATTR_SIZE_VER0
store i32 %12, i32* %11
%13 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 4
%14 = load i32, i32* %3
%15 = icmp ugt i32 %14, 10
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* @PERF_TYPE_RAW
br label %20
18: ; preds = %2
%19 = load i32, i32* @PERF_TYPE_HARDWARE
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ %17, %16 ], [ %19, %18 ]
store i32 %21, i32* %13
%22 = load %struct.rdpmc_ctx*, %struct.rdpmc_ctx** %4
%23 = call i32 @rdpmc_open_attr(%struct.perf_event_attr* %5, %struct.rdpmc_ctx* %22, i32* null)
ret i32 %23
}

LLVM IR (-O2):
%struct.rdpmc_ctx = type { i32 }
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@PERF_SAMPLE_READ = global i32 0
@PERF_ATTR_SIZE_VER0 = global i32 0
@PERF_TYPE_RAW = global i32 0
@PERF_TYPE_HARDWARE = global i32 0
define i32 @rdpmc_open(i32 %0, %struct.rdpmc_ctx* %1) {
%3 = alloca %struct.perf_event_attr
%4 = bitcast %struct.perf_event_attr* %3 to i8*
%5 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 1
store i32 1, i32* %6
%7 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 2
%8 = load i32, i32* @PERF_SAMPLE_READ
store i32 %8, i32* %7
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 3
%10 = load i32, i32* @PERF_ATTR_SIZE_VER0
store i32 %10, i32* %9
%11 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 4
%12 = icmp ugt i32 %0, 10
%13 = load i32, i32* @PERF_TYPE_RAW
%14 = load i32, i32* @PERF_TYPE_HARDWARE
%15 = select i1 %12, i32 %13, i32 %14
store i32 %15, i32* %11
%16 = call i32 @rdpmc_open_attr(%struct.perf_event_attr* %3, %struct.rdpmc_ctx* %1, i32* null)
ret i32 %16
}