#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 stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int stat(char *, struct stat *);
int open_cpuset(const char *path, const char *name) {
  char buf[1024];
  struct stat st;
  int ret;
  int fd;
  buf[1024 - 1] = 0;
  snprintf(buf, 1024 - 1, "%s/%s", path, name);
  ret = stat(buf, &st);
  if (ret < 0)
    return ret;
  fd = open(buf, O_WRONLY);
  return fd;
}


x86 assembly (clang, -O0):
<open_cpuset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x3ff,%esi
lea    0xe9e(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x428(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    119b <open_cpuset+0x6b>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <open_cpuset+0x8f>
lea    -0x420(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x430(%rbp)
mov    -0x430(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_cpuset>:
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r8
mov    %rdi,%rcx
movb   $0x0,0x40f(%rsp)
lea    0xeb3(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1030 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %eax,%eax
js     1183 <open_cpuset+0x53>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1050 <open@plt>
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
define i32 @open_cpuset(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 1023
store i8 0, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @snprintf(i8* %11, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @stat(i8* %15, %struct.stat* %7)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i32, i32* %8
store i32 %20, i32* %3
br label %26
21: ; preds = %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
store i32 %25, i32* %3
br label %26
26: ; preds = %21, %19
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
define i32 @open_cpuset(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %7
%8 = call i32 @snprintf(i8* %5, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = call i32 @stat(i8* %5, %struct.stat* %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* %5, i32 %12)
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ %13, %11 ], [ %9, %2 ]
ret i32 %15
}