#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int close(int);
int connect_to_gateway(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *read_line(int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ write_line(int, char *);
void guests(char *hostname) {
  int server_socket;
  char *request = "guests\n\n";
  char *line;
  server_socket = connect_to_gateway(hostname);
  write_line(server_socket, request);
  line = read_line(server_socket);
  if (!line) {
    fprintf(stderr, "Cannot read response\n");
    exit(EXIT_FAILURE);
  }
  if (*line != '0') {
    if (strlen(line) > 2) {
      if (*line == '1') {
        fprintf(stderr, "%s\n", line + 2);
      } else {
        fprintf(stderr, "Error response: %s\n", line + 2);
      }
    } else {
      fprintf(stderr, "Cannot read response\n");
    }
    exit(EXIT_FAILURE);
  }
  do {
    free(line);
    line = read_line(server_socket);
    if (!line) {
      fprintf(stderr, "Cannot read response\n");
      exit(EXIT_FAILURE);
    }
    if (strlen(line) > 0) {
      printf("%s\n", line);
    }
  } while (strlen(line) > 0);
  free(line);
  if (close(server_socket) == -1) {
    perror("Error closing connection");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<guests>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe4d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <connect_to_gateway@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10c0 <write_line@plt>
mov    -0xc(%rbp),%edi
call   1080 <read_line@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120b <guests+0x6b>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     12ab <guests+0x10b>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jle    1286 <guests+0xe6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1262 <guests+0xc2>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
add    $0x2,%rdx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1281 <guests+0xe1>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
add    $0x2,%rdx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    129d <guests+0xfd>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    12b0 <guests+0x110>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
call   1080 <read_line@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12f5 <guests+0x155>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    1318 <guests+0x178>
mov    -0x20(%rbp),%rsi
lea    0xd1c(%rip),%rdi
call   1050 <printf@plt>
jmp    131d <guests+0x17d>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jg     12b0 <guests+0x110>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1364 <guests+0x1c4>
lea    0xce2(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guests>:
push   %rbp
push   %r14
push   %rbx
call   10a0 <connect_to_gateway@plt>
mov    %eax,%ebp
lea    0xe4e(%rip),%rsi
mov    %eax,%edi
call   10c0 <write_line@plt>
mov    %ebp,%edi
call   1080 <read_line@plt>
test   %rax,%rax
je     1261 <guests+0xc1>
mov    %rax,%rbx
mov    (%rax),%r14b
cmp    $0x30,%r14b
jne    1237 <guests+0x97>
lea    0xe53(%rip),%r14
jmp    11ed <guests+0x4d>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    121e <guests+0x7e>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <read_line@plt>
test   %rax,%rax
je     1261 <guests+0xc1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11e0 <guests+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11e0 <guests+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
je     1286 <guests+0xe6>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x3,%rax
jl     1261 <guests+0xc1>
add    $0x2,%rbx
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
cmp    $0x31,%r14b
jne    1294 <guests+0xf4>
lea    0xdd0(%rip),%rsi
jmp    129b <guests+0xfb>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xda6(%rip),%rdi
call   1090 <perror@plt>
jmp    1278 <guests+0xd8>
lea    0xd84(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1278 <guests+0xd8>

LLVM IR (-O0):
@.str = [9 x i8] c"guests\0A\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Cannot read response\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [20 x i8] c"Error response: %s\0A\00"
@.str.4 = [25 x i8] c"Error closing connection\00"
define void @guests(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %2
%7 = call i32 @connect_to_gateway(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = load i8*, i8** %4
%10 = call i32 @write_line(i32 %8, i8* %9)
%11 = load i32, i32* %3
%12 = call i8* @read_line(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %1
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 48
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = icmp sgt i64 %27, 2
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 49
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %44
39: ; preds = %29
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39, %34
br label %48
45: ; preds = %25
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %45, %44
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %20
br label %52
52: ; preds = %72, %51
%53 = load i8*, i8** %5
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %3
%56 = call i8* @read_line(i32 %55)
store i8* %56, i8** %5
%57 = load i8*, i8** %5
%58 = icmp ne i8* %57, null
br i1 %58, label %64, label %59
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %52
%65 = load i8*, i8** %5
%66 = call i64 @strlen(i8* %65)
%67 = icmp sgt i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i8*, i8** %5
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %68, %64
br label %72
72: ; preds = %71
%73 = load i8*, i8** %5
%74 = call i64 @strlen(i8* %73)
%75 = icmp sgt i64 %74, 0
br i1 %75, label %52, label %76
76: ; preds = %72
%77 = load i8*, i8** %5
%78 = call i32 @free(i8* %77)
%79 = load i32, i32* %3
%80 = call i32 @close(i32 %79)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %76
%83 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %76
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"guests\0A\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Cannot read response\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [20 x i8] c"Error response: %s\0A\00"
@.str.4 = [25 x i8] c"Error closing connection\00"
define void @guests(i8* %0) {
%2 = tail call i32 @connect_to_gateway(i8* %0)
%3 = tail call i32 @write_line(i32 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @read_line(i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i8, i8* %4
%13 = icmp eq i8 %12, 48
br i1 %13, label %31, label %14
14: ; preds = %11
%15 = tail call i64 @strlen(i8* %4)
%16 = icmp sgt i64 %15, 2
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = icmp eq i8 %12, 49
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds i8, i8* %4, i64 2
br i1 %18, label %21, label %23
21: ; preds = %17
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %28
23: ; preds = %17
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %28
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %21, %23, %25
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %11, %46
%32 = phi i8* [ %34, %46 ], [ %4, %11 ]
%33 = tail call i32 @free(i8* %32)
%34 = tail call i8* @read_line(i32 %2)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %31
%42 = tail call i64 @strlen(i8* %34)
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %46
46: ; preds = %41, %44
%47 = tail call i64 @strlen(i8* %34)
%48 = icmp sgt i64 %47, 0
br i1 %48, label %31, label %49
49: ; preds = %46
%50 = tail call i32 @free(i8* %34)
%51 = tail call i32 @close(i32 %2)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = tail call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
ret void
}