#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 IPC_CREAT;
int /*<<< orphan*/ elog(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int, int, int);
int sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int do_quit(int fd, char *param) {
  send(fd, "221 JChen\r\n", strlen("221 JChen\r\n"), 0);
  int shmid = shmget(1234, 512, IPC_CREAT | 0600);
  int *max = shmat(shmid, NULL, 0);
  (*max)--;
  do {
    char format_msg[1024] = {0};
    int i = sprintf(format_msg, "[%s %s:%d]:", "08:25:37",
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/sundyCoder/STMP_POP3/"
                    "refs/heads/master/smtpserver/smtp_ser.c",
                    470);
    sprintf(format_msg + i, "a client disconnected!current client num=%d\n",
            *max);
    elog(format_msg);
  } while (0);
  printf("fd = %d\n", fd);
  return 0;
}


x86 assembly (clang, -O0):
<do_quit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x428(%rbp)
lea    0xe5e(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x428(%rbp),%edi
mov    %eax,%edx
lea    0xe4a(%rip),%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
or     $0x180,%edx
mov    $0x4d2,%edi
mov    $0x200,%esi
call   1090 <shmget@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
lea    0xdf0(%rip),%rsi
lea    0xdf5(%rip),%rdx
lea    0xdf7(%rip),%rcx
mov    $0x1d6,%r8d
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
movslq -0x424(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1070 <elog@plt>
mov    -0x4(%rbp),%esi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_quit>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
lea    0xe6b(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    0x2e2d(%rip),%rax
mov    $0x180,%edx
or     (%rax),%edx
mov    $0x4d2,%edi
mov    $0x200,%esi
call   1090 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <shmat@plt>
mov    %rax,%rbp
addl   $0xffffffff,(%rax)
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe19(%rip),%rsi
lea    0xe1e(%rip),%rdx
lea    0xe20(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1d6,%r8d
xor    %eax,%eax
call   10a0 <sprintf@plt>
cltq
lea    (%rsp,%rax,1),%rdi
mov    0x0(%rbp),%edx
lea    0xe97(%rip),%rsi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <elog@plt>
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"221 JChen\0D\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [12 x i8] c"[%s %s:%d]:\00"
@.str.2 = [9 x i8] c"08:25:37\00"
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/sundyCoder/STMP_POP3/refs/heads/master/smtpserver/smtp_ser.c\00"
@.str.4 = [45 x i8] c"a client disconnected!current client num=%d\0A\00"
@.str.5 = [9 x i8] c"fd = %d\0A\00"
define i32 @do_quit(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
%10 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @send(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10, i32 0)
%12 = load i32, i32* @IPC_CREAT
%13 = or i32 %12, 384
%14 = call i32 @shmget(i32 1234, i32 512, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = call i32* @shmat(i32 %15, i32* null, i32 0)
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = add nsw i32 %18, -1
store i32 %19, i32* %17
br label %20
20: ; preds = %2
%21 = bitcast [1024 x i8]* %7 to i8*
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0), i32 470)
store i32 %23, i32* %8
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = call i32 @elog(i8* %31)
br label %33
33: ; preds = %20
%34 = load i32, i32* %3
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"221 JChen\0D\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [12 x i8] c"[%s %s:%d]:\00"
@.str.2 = [9 x i8] c"08:25:37\00"
@.str.3 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/sundyCoder/STMP_POP3/refs/heads/master/smtpserver/smtp_ser.c\00"
@.str.4 = [45 x i8] c"a client disconnected!current client num=%d\0A\00"
@.str.5 = [9 x i8] c"fd = %d\0A\00"
define i32 @do_quit(i32 %0, i8* nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0)
%6 = load i32, i32* @IPC_CREAT
%7 = or i32 %6, 384
%8 = tail call i32 @shmget(i32 1234, i32 512, i32 %7)
%9 = tail call i32* @shmat(i32 %8, i32* null, i32 0)
%10 = load i32, i32* %9
%11 = add nsw i32 %10, -1
store i32 %11, i32* %9
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.3, i64 0, i64 0), i32 470)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %14
%16 = load i32, i32* %9
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = call i32 @elog(i8* %12)
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %0)
ret i32 0
}