#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 st_size;
};

/* Variables and functions */
scalar_t__ EAGAIN;
int ENOMEM;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int get_transfer_description(char **desc, char *path) {
  int ret = EXIT_FAILURE;
  int len = strlen(path);
  struct stat st;
  int cc = 0;
  char *buffer = NULL;
  int fd = -1;
  strcat(path, "/description.txt");
  if (stat(path, &st) == -1)
    goto err;
  fd = open(path, O_RDONLY);
  if (fd == -1)
    goto err;
  buffer = calloc(st.st_size + 1, sizeof(*buffer));
  if (buffer == NULL)
    return ENOMEM;
  do {
    ret = read(fd, buffer + cc, st.st_size - cc);
    if (ret < 0) {
      if (errno == EAGAIN)
        continue;
      goto err;
    }
    cc += ret;
  } while (cc < st.st_size && ret > 0);
  if (cc < st.st_size) {
    ret = EXIT_FAILURE;
    goto err;
  }
  *desc = buffer;
  buffer = NULL;
  ret = EXIT_SUCCESS;
err:
  path[len] = '\0';
  if (buffer)
    free(buffer);
  if (fd != -1)
    close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<get_transfer_description>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    11e9 <get_transfer_description+0x69>
jmp    12f7 <get_transfer_description+0x177>
mov    -0x18(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    120d <get_transfer_description+0x8d>
jmp    12f7 <get_transfer_description+0x177>
mov    -0x28(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123d <get_transfer_description+0xbd>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    132f <get_transfer_description+0x1af>
jmp    1242 <get_transfer_description+0xc2>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
mov    -0x28(%rbp),%edx
sub    -0x2c(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    128c <get_transfer_description+0x10c>
mov    0x2d61(%rip),%rax
mov    (%rax),%rax
mov    0x2d37(%rip),%rcx
cmp    (%rcx),%rax
jne    1287 <get_transfer_description+0x107>
jmp    1295 <get_transfer_description+0x115>
jmp    12f7 <get_transfer_description+0x177>
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x28(%rbp),%ecx
mov    %al,-0x3d(%rbp)
jge    12b0 <get_transfer_description+0x130>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    1242 <get_transfer_description+0xc2>
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12d8 <get_transfer_description+0x158>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12f7 <get_transfer_description+0x177>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x38(%rbp)
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x38(%rbp)
je     1317 <get_transfer_description+0x197>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xffffffff,-0x3c(%rbp)
je     1329 <get_transfer_description+0x1a9>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_transfer_description>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe52(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1080 <stat@plt>
mov    $0xffffffff,%r13d
cmp    $0xffffffff,%eax
je     1290 <get_transfer_description+0x110>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1290 <get_transfer_description+0x110>
mov    %eax,%r13d
mov    %r14,0x10(%rsp)
mov    %ebp,0x4(%rsp)
mov    0x8(%rsp),%r14d
lea    0x1(%r14),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1255 <get_transfer_description+0xd5>
mov    %rax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
lea    (%r15,%rax,1),%rsi
mov    %r14d,%edx
sub    %eax,%edx
mov    %r13d,%edi
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1260 <get_transfer_description+0xe0>
add    %ebx,%ebp
test   %ebx,%ebx
je     1245 <get_transfer_description+0xc5>
cmp    %r14d,%ebp
jl     1220 <get_transfer_description+0xa0>
cmp    %r14d,%ebp
jge    127b <get_transfer_description+0xfb>
mov    0x2d77(%rip),%rax
mov    (%rax),%ebx
jmp    12b7 <get_transfer_description+0x137>
mov    0x2d7c(%rip),%rax
mov    (%rax),%ebx
jmp    12a6 <get_transfer_description+0x126>
mov    0x2d69(%rip),%rax
mov    (%rax),%rax
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%rax
jne    12b7 <get_transfer_description+0x137>
cmp    %ebp,%r14d
jg     124a <get_transfer_description+0xca>
mov    0x10(%rsp),%rax
mov    %r15,(%rax)
mov    0x2d36(%rip),%rax
mov    (%rax),%ebx
mov    0x4(%rsp),%ebp
movslq %ebp,%rax
movb   $0x0,(%r12,%rax,1)
cmp    $0xffffffff,%r13d
je     12a6 <get_transfer_description+0x126>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq 0x4(%rsp),%rax
movb   $0x0,(%r12,%rax,1)
mov    %r15,%rdi
call   1030 <free@plt>
cmp    $0xffffffff,%r13d
jne    129e <get_transfer_description+0x11e>
jmp    12a6 <get_transfer_description+0x126>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [17 x i8] c"/description.txt\00"
@O_RDONLY = global i32 0
@ENOMEM = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @get_transfer_description(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %6
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
store i32 0, i32* %9
store i8* null, i8** %10
store i32 -1, i32* %11
%15 = load i8*, i8** %5
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %5
%18 = call i32 @stat(i8* %17, %struct.stat* %8)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %2
br label %82
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %21
br label %82
28: ; preds = %21
%29 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
%32 = call i8* @calloc(i32 %31, i32 1)
store i8* %32, i8** %10
%33 = load i8*, i8** %10
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = load i32, i32* @ENOMEM
store i32 %36, i32* %3
br label %100
37: ; preds = %28
br label %38
38: ; preds = %69, %37
%39 = load i32, i32* %11
%40 = load i8*, i8** %10
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load i32, i32* %9
%47 = sub nsw i32 %45, %46
%48 = call i32 @read(i32 %39, i8* %43, i32 %47)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %57
51: ; preds = %38
%52 = load i64, i64* @errno
%53 = load i64, i64* @EAGAIN
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %51
br label %61
56: ; preds = %51
br label %82
57: ; preds = %38
%58 = load i32, i32* %6
%59 = load i32, i32* %9
%60 = add nsw i32 %59, %58
store i32 %60, i32* %9
br label %61
61: ; preds = %57, %55
%62 = load i32, i32* %9
%63 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%64 = load i32, i32* %63
%65 = icmp slt i32 %62, %64
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = load i32, i32* %6
%68 = icmp sgt i32 %67, 0
br label %69
69: ; preds = %66, %61
%70 = phi i1 [ false, %61 ], [ %68, %66 ]
br i1 %70, label %38, label %71
71: ; preds = %69
%72 = load i32, i32* %9
%73 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%74 = load i32, i32* %73
%75 = icmp slt i32 %72, %74
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %6
br label %82
78: ; preds = %71
%79 = load i8*, i8** %10
%80 = load i8**, i8*** %4
store i8* %79, i8** %80
store i8* null, i8** %10
%81 = load i32, i32* @EXIT_SUCCESS
store i32 %81, i32* %6
br label %82
82: ; preds = %78, %76, %56, %27, %20
%83 = load i8*, i8** %5
%84 = load i32, i32* %7
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8 0, i8* %86
%87 = load i8*, i8** %10
%88 = icmp ne i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %82
%90 = load i8*, i8** %10
%91 = call i32 @free(i8* %90)
br label %92
92: ; preds = %89, %82
%93 = load i32, i32* %11
%94 = icmp ne i32 %93, -1
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i32, i32* %11
%97 = call i32 @close(i32 %96)
br label %98
98: ; preds = %95, %92
%99 = load i32, i32* %6
store i32 %99, i32* %3
br label %100
100: ; preds = %98, %35
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [17 x i8] c"/description.txt\00"
@O_RDONLY = global i32 0
@ENOMEM = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EXIT_SUCCESS = global i32 0
define i32 @get_transfer_description(i8** nocapture writeonly %0, i8* %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @strlen(i8* %1)
%6 = bitcast %struct.stat* %3 to i8*
%7 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @stat(i8* %1, %struct.stat* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %45, label %10
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %1, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %45, label %14
14: ; preds = %10
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = tail call i8* @calloc(i32 %17, i32 1)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i32, i32* @ENOMEM
br label %61
22: ; preds = %14, %35
%23 = phi i32 [ %36, %35 ], [ 0, %14 ]
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %18, i64 %24
%26 = sub nsw i32 %16, %23
%27 = tail call i32 @read(i32 %12, i8* %25, i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %22
%30 = load i64, i64* @errno
%31 = load i64, i64* @EAGAIN
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %50
33: ; preds = %29
%34 = icmp sgt i32 %16, %23
br i1 %34, label %41, label %43
35: ; preds = %22
%36 = add nsw i32 %27, %23
%37 = icmp slt i32 %36, %16
%38 = icmp ne i32 %27, 0
%39 = and i1 %38, %37
br i1 %39, label %22, label %40
40: ; preds = %35
br i1 %37, label %41, label %43
41: ; preds = %33, %40
%42 = load i32, i32* @EXIT_FAILURE
br label %50
43: ; preds = %33, %40
store i8* %18, i8** %0
%44 = load i32, i32* @EXIT_SUCCESS
br label %45
45: ; preds = %2, %10, %43
%46 = phi i32 [ %44, %43 ], [ %4, %10 ], [ %4, %2 ]
%47 = phi i32 [ %12, %43 ], [ -1, %10 ], [ -1, %2 ]
%48 = sext i32 %5 to i64
%49 = getelementptr inbounds i8, i8* %1, i64 %48
store i8 0, i8* %49
br label %55
50: ; preds = %29, %41
%51 = phi i32 [ %42, %41 ], [ %27, %29 ]
%52 = sext i32 %5 to i64
%53 = getelementptr inbounds i8, i8* %1, i64 %52
store i8 0, i8* %53
%54 = tail call i32 @free(i8* %18)
br label %55
55: ; preds = %45, %50
%56 = phi i32 [ %47, %45 ], [ %12, %50 ]
%57 = phi i32 [ %46, %45 ], [ %51, %50 ]
%58 = icmp eq i32 %56, -1
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = tail call i32 @close(i32 %56)
br label %61
61: ; preds = %55, %59, %20
%62 = phi i32 [ %21, %20 ], [ %57, %59 ], [ %57, %55 ]
ret i32 %62
}