#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 */

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
char *gds_read_libname(int fd, int count, int verbose) {
  char *name;
  name = (char *)malloc(count - 3);
  read(fd, name, count - 4);
  name[count - 4] = '\0';
  if (verbose)
    printf("             library \"%s\"\n", name);
  return (name);
}


x86 assembly (clang, -O0):
<gds_read_libname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
sub    $0x4,%edx
call   1040 <read@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0xc(%rbp)
je     118d <gds_read_libname+0x5d>
mov    -0x18(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gds_read_libname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
lea    -0x3(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movslq %ebp,%rbp
lea    -0x4(%rbp),%rdx
mov    %r15d,%edi
mov    %rax,%rsi
call   1040 <read@plt>
movb   $0x0,-0x4(%rbx,%rbp,1)
test   %r14d,%r14d
je     1175 <gds_read_libname+0x45>
lea    0xe93(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c" library \22%s\22\0A\00"
define i8* @gds_read_libname(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = sub nsw i32 %8, 3
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %7
%12 = load i32, i32* %4
%13 = load i8*, i8** %7
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 4
%16 = call i32 @read(i32 %12, i8* %13, i32 %15)
%17 = load i8*, i8** %7
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i8*, i8** %7
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %3
%28 = load i8*, i8** %7
ret i8* %28
}

LLVM IR (-O2):
@.str = [27 x i8] c" library \22%s\22\0A\00"
define i8* @gds_read_libname(i32 %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, -3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = add nsw i32 %1, -4
%8 = tail call i32 @read(i32 %0, i8* %6, i32 %7)
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
%11 = icmp eq i32 %2, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %14
14: ; preds = %12, %3
ret i8* %6
}