#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int strlen(char *);
int get_uuid_by_docker_cpuset(char *uuid, int uuid_size) {
  FILE *fd;
  int ret = -1;
  char *cmd = "cat /proc/self/cpuset";
  if ((fd = popen(cmd, "r")) == NULL) {
    goto out;
  }
  if (fgets(uuid, uuid_size, fd) == NULL) {
    goto out;
  }
  if (strlen(uuid) <= 2) {
    goto out;
  }
  uuid[strlen(uuid) - 1] = '\0';
  ret = 0;
out:
  pclose(fd);
  return ret;
}


x86 assembly (clang, -O0):
<get_uuid_by_docker_cpuset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1184 <get_uuid_by_docker_cpuset+0x44>
jmp    11e2 <get_uuid_by_docker_cpuset+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11a3 <get_uuid_by_docker_cpuset+0x63>
jmp    11e2 <get_uuid_by_docker_cpuset+0xa2>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jg     11ba <get_uuid_by_docker_cpuset+0x7a>
jmp    11e2 <get_uuid_by_docker_cpuset+0xa2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uuid_by_docker_cpuset>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xead(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%rbx
mov    $0xffffffff,%r15d
test   %rax,%rax
je     119f <get_uuid_by_docker_cpuset+0x5f>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     119f <get_uuid_by_docker_cpuset+0x5f>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     119f <get_uuid_by_docker_cpuset+0x5f>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"cat /proc/self/cpuset\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_uuid_by_docker_cpuset(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %6
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i8*, i8** %7
%9 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %31
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = load i32*, i32** %5
%16 = call i32* @fgets(i8* %13, i32 %14, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
br label %31
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = icmp sle i32 %21, 2
br i1 %22, label %23, label %24
23: ; preds = %19
br label %31
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
store i8 0, i8* %30
store i32 0, i32* %6
br label %31
31: ; preds = %24, %23, %18, %11
%32 = load i32*, i32** %5
%33 = call i32 @pclose(i32* %32)
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
@.str = [22 x i8] c"cat /proc/self/cpuset\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_uuid_by_docker_cpuset(i8* %0, i32 %1) {
%3 = tail call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i32* @fgets(i8* %0, i32 %1, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp slt i32 %9, 3
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %8, %5, %2, %11
%17 = phi i32 [ -1, %2 ], [ -1, %5 ], [ -1, %8 ], [ 0, %11 ]
%18 = tail call i32 @pclose(i32* %3)
ret i32 %17
}