#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 string_t {
  int dummy;
};
typedef int /*<<< orphan*/ gzFile;

/* Variables and functions */
int /*<<< orphan*/ free_string(struct string_t *);
int gzread(int /*<<< orphan*/, char *, int);
struct string_t *new_string();
int /*<<< orphan*/ string_cat_char(struct string_t *, char);
struct string_t *gzread_string(gzFile file) {
  struct string_t *string = new_string();
  char cc;
  while (gzread(file, &cc, 1) == 1) {
    if (!cc)
      return string;
    string_cat_char(string, cc);
  }
  free_string(string);
  return NULL;
}


x86 assembly (clang, -O0):
<gzread_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <new_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1040 <gzread@plt>
cmp    $0x1,%eax
jne    1199 <gzread_string+0x59>
cmpb   $0x0,-0x19(%rbp)
jne    1187 <gzread_string+0x47>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <gzread_string+0x6a>
mov    -0x18(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1050 <string_cat_char@plt>
jmp    1156 <gzread_string+0x16>
mov    -0x18(%rbp),%rdi
call   1060 <free_string@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzread_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <new_string@plt>
mov    %rax,%rbx
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <gzread@plt>
cmp    $0x1,%eax
jne    1198 <gzread_string+0x58>
lea    0xf(%rsp),%r14
nop
movzbl 0xf(%rsp),%eax
test   %al,%al
je     11a2 <gzread_string+0x62>
movsbl %al,%esi
mov    %rbx,%rdi
call   1050 <string_cat_char@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <gzread@plt>
cmp    $0x1,%eax
je     1170 <gzread_string+0x30>
mov    %rbx,%rdi
call   1060 <free_string@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.string_t = type { i32 }
define %struct.string_t* @gzread_string(i32 %0) {
%2 = alloca %struct.string_t*
%3 = alloca i32
%4 = alloca %struct.string_t*
%5 = alloca i8
store i32 %0, i32* %3
%6 = call %struct.string_t* (...) @new_string()
store %struct.string_t* %6, %struct.string_t** %4
br label %7
7: ; preds = %16, %1
%8 = load i32, i32* %3
%9 = call i32 @gzread(i32 %8, i8* %5, i32 1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i8, i8* %5
%13 = icmp ne i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load %struct.string_t*, %struct.string_t** %4
store %struct.string_t* %15, %struct.string_t** %2
br label %23
16: ; preds = %11
%17 = load %struct.string_t*, %struct.string_t** %4
%18 = load i8, i8* %5
%19 = call i32 @string_cat_char(%struct.string_t* %17, i8 signext %18)
br label %7
20: ; preds = %7
%21 = load %struct.string_t*, %struct.string_t** %4
%22 = call i32 @free_string(%struct.string_t* %21)
store %struct.string_t* null, %struct.string_t** %2
br label %23
23: ; preds = %20, %14
%24 = load %struct.string_t*, %struct.string_t** %2
ret %struct.string_t* %24
}

LLVM IR (-O2):
%struct.string_t = type { i32 }
define %struct.string_t* @gzread_string(i32 %0) {
%2 = alloca i8
%3 = tail call %struct.string_t* (...) @new_string()
%4 = call i32 @gzread(i32 %0, i8* %2, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %13
6: ; preds = %1, %9
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = call i32 @string_cat_char(%struct.string_t* %3, i8 signext %7)
%11 = call i32 @gzread(i32 %0, i8* %2, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %6, label %13
13: ; preds = %9, %1
%14 = call i32 @free_string(%struct.string_t* %3)
br label %15
15: ; preds = %6, %13
%16 = phi %struct.string_t* [ null, %13 ], [ %3, %6 ]
ret %struct.string_t* %16
}