#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*/ logging(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, char *);
int socket_accept(int);
int /*<<< orphan*/ user_enter(int);
void guest_new(int fd_server) {
  int fd_guest = -1;
  do {
    fd_guest = socket_accept(fd_server);
    if (fd_guest > 0) {
      char str_buf[128 * 2];
      user_enter(fd_guest);
      snprintf(str_buf, 128 * 2, "<- socket[%d] %s", fd_guest, "entered.");
      logging(str_buf);
    }
  } while (fd_guest != -1);
}


x86 assembly (clang, -O0):
<guest_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <socket_accept@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11a0 <guest_new+0x60>
mov    -0x8(%rbp),%edi
call   1030 <user_enter@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe78(%rip),%rdx
lea    0xe82(%rip),%r8
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <logging@plt>
jmp    11a5 <guest_new+0x65>
cmpl   $0xffffffff,-0x8(%rbp)
jne    1155 <guest_new+0x15>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guest_new>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
lea    0xea8(%rip),%r14
lea    0xeb2(%rip),%r15
mov    %rsp,%r12
jmp    1175 <guest_new+0x35>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xffffffff,%ebp
je     11a8 <guest_new+0x68>
mov    %ebx,%edi
call   1040 <socket_accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1170 <guest_new+0x30>
mov    %ebp,%edi
call   1030 <user_enter@plt>
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1060 <logging@plt>
jmp    1170 <guest_new+0x30>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"<- socket[%d] %s\00"
@.str.1 = [9 x i8] c"entered.\00"
define void @guest_new(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 %0, i32* %2
store i32 -1, i32* %3
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %2
%7 = call i32 @socket_accept(i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = load i32, i32* %3
%12 = call i32 @user_enter(i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @snprintf(i8* %13, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i32 @logging(i8* %16)
br label %18
18: ; preds = %10, %5
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, -1
br i1 %21, label %5, label %22
22: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"<- socket[%d] %s\00"
@.str.1 = [9 x i8] c"entered.\00"
define void @guest_new(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %11, %1
%5 = call i32 @socket_accept(i32 %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = call i32 @user_enter(i32 %5)
%9 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @logging(i8* %3)
br label %11
11: ; preds = %4, %7
%12 = icmp eq i32 %5, -1
br i1 %12, label %13, label %4
13: ; preds = %11
ret void
}