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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ print_quoted_string(char *, unsigned int,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ tprintf(char *, unsigned long, ...);
int /*<<< orphan*/ tprints(char *);
scalar_t__ umoven(struct tcb *, unsigned long, unsigned int, char *);
void print_xattr_val(struct tcb *tcp, int failed, unsigned long arg,
                     unsigned long insize, unsigned long size) {
  char *buf;
  unsigned int len;
  if (insize == 0)
    goto failed;
  len = size;
  if (size != (unsigned long)len)
    goto failed;
  if (!len) {
    tprintf(", \"\", %ld", insize);
    return;
  }
  buf = malloc(len);
  if (!buf)
    goto failed;
  if (umoven(tcp, arg, len, buf) < 0) {
    free(buf);
    goto failed;
  }
  if (buf[len - 1] == '\0')
    --len;
  tprints(", ");
  print_quoted_string(buf, len, 0);
  tprintf(", %ld", insize);
  free(buf);
  return;
failed:
  tprintf(", 0x%lx, %ld", arg, insize);
}


x86 assembly (clang, -O0):
<print_xattr_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <print_xattr_val+0x2b>
jmp    126c <print_xattr_val+0x10c>
mov    -0x28(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
cmp    %rcx,%rax
je     11a7 <print_xattr_val+0x47>
jmp    126c <print_xattr_val+0x10c>
cmpl   $0x0,-0x34(%rbp)
jne    11c8 <print_xattr_val+0x68>
mov    -0x20(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <tprintf@plt>
jmp    1282 <print_xattr_val+0x122>
mov    -0x34(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e4 <print_xattr_val+0x84>
jmp    126c <print_xattr_val+0x10c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1040 <umoven@plt>
cmp    $0x0,%rax
jge    1210 <print_xattr_val+0xb0>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    126c <print_xattr_val+0x10c>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1232 <print_xattr_val+0xd2>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
lea    0xdd1(%rip),%rdi
call   1080 <tprints@plt>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
xor    %edx,%edx
call   1070 <print_quoted_string@plt>
mov    -0x20(%rbp),%rsi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <tprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1282 <print_xattr_val+0x122>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1050 <tprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_xattr_val>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
test   %rcx,%rcx
je     1220 <print_xattr_val+0xc0>
mov    %r8,%rbx
mov    %r8,%rax
shr    $0x20,%rax
jne    1220 <print_xattr_val+0xc0>
test   %ebx,%ebx
je     11fe <print_xattr_val+0x9e>
mov    %rdi,%r13
mov    %ebx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1220 <print_xattr_val+0xc0>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %rax,%rcx
call   1040 <umoven@plt>
test   %rax,%rax
js     1218 <print_xattr_val+0xb8>
mov    %ebx,%eax
add    $0xffffffff,%eax
cmpb   $0x1,(%r12,%rax,1)
sbb    $0x0,%ebx
lea    0xe3f(%rip),%rdi
call   1080 <tprints@plt>
mov    %r12,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1070 <print_quoted_string@plt>
lea    0xe21(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <tprintf@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xdfb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <tprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xde6(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <tprintf@plt>

LLVM IR (-O0):
%struct.tcb = type { i32 }
@.str = [10 x i8] c", \22\22, %ld\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [6 x i8] c", %ld\00"
@.str.3 = [13 x i8] c", 0x%lx, %ld\00"
define void @print_xattr_val(%struct.tcb* %0, i32 %1, i64 %2, i64 %3, i64 %4) {
%6 = alloca %struct.tcb*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
store %struct.tcb* %0, %struct.tcb** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%13 = load i64, i64* %9
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %5
br label %67
16: ; preds = %5
%17 = load i64, i64* %10
%18 = trunc i64 %17 to i32
store i32 %18, i32* %12
%19 = load i64, i64* %10
%20 = load i32, i32* %12
%21 = zext i32 %20 to i64
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %16
br label %67
24: ; preds = %16
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i64, i64* %9
%29 = call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %28)
br label %71
30: ; preds = %24
%31 = load i32, i32* %12
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %11
%33 = load i8*, i8** %11
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %30
br label %67
36: ; preds = %30
%37 = load %struct.tcb*, %struct.tcb** %6
%38 = load i64, i64* %8
%39 = load i32, i32* %12
%40 = load i8*, i8** %11
%41 = call i64 @umoven(%struct.tcb* %37, i64 %38, i32 %39, i8* %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load i8*, i8** %11
%45 = call i32 @free(i8* %44)
br label %67
46: ; preds = %36
%47 = load i8*, i8** %11
%48 = load i32, i32* %12
%49 = sub i32 %48, 1
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = load i32, i32* %12
%57 = add i32 %56, -1
store i32 %57, i32* %12
br label %58
58: ; preds = %55, %46
%59 = call i32 @tprints(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%60 = load i8*, i8** %11
%61 = load i32, i32* %12
%62 = call i32 @print_quoted_string(i8* %60, i32 %61, i32 0)
%63 = load i64, i64* %9
%64 = call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %63)
%65 = load i8*, i8** %11
%66 = call i32 @free(i8* %65)
br label %71
67: ; preds = %43, %35, %23, %15
%68 = load i64, i64* %8
%69 = load i64, i64* %9
%70 = call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i64 %68, i64 %69)
br label %71
71: ; preds = %67, %58, %27
ret void
}

LLVM IR (-O2):
%struct.tcb = type { i32 }
@.str = [10 x i8] c", \22\22, %ld\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [6 x i8] c", %ld\00"
@.str.3 = [13 x i8] c", 0x%lx, %ld\00"
define void @print_xattr_val(%struct.tcb* %0, i32 %1, i64 %2, i64 %3, i64 %4) {
%6 = icmp eq i64 %3, 0
br i1 %6, label %34, label %7
7: ; preds = %5
%8 = trunc i64 %4 to i32
%9 = icmp ult i64 %4, 4294967296
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = icmp eq i32 %8, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %3)
br label %36
14: ; preds = %10
%15 = tail call i8* @malloc(i32 %8)
%16 = icmp eq i8* %15, null
br i1 %16, label %34, label %17
17: ; preds = %14
%18 = tail call i64 @umoven(%struct.tcb* %0, i64 %2, i32 %8, i8* %15)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @free(i8* %15)
br label %34
22: ; preds = %17
%23 = add nuw nsw i64 %4, 4294967295
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds i8, i8* %15, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
%28 = sext i1 %27 to i32
%29 = add i32 %28, %8
%30 = tail call i32 @tprints(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @print_quoted_string(i8* %15, i32 %29, i32 0)
%32 = tail call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %3)
%33 = tail call i32 @free(i8* %15)
br label %36
34: ; preds = %14, %7, %5, %20
%35 = tail call i32 (i8*, i64, ...) @tprintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i64 %2, i64 %3)
br label %36
36: ; preds = %34, %22, %12
ret void
}