// File: /workspace/github_c_makefile_star2_O0/liuhaotian[P]xmppsh/xmppsh.c
// Function: main
int main(int argc, char **argv)
{
    xmpp_ctx_t *ctx;
    xmpp_conn_t *conn;
    xmpp_log_t *log;
    char jid[20], pass[20];





	if(!RedirStatus){
		pipe(pipeo2i);
		pipe(pipei2o);

		fcntl(pipei2o[0], F_SETFL, O_NONBLOCK);

		standardout = dup(1);
		standardin  = dup(0);

		RedirStatus = 1;

		pid = fork();
		if (pid >= 0) // fork succeeds
		{
			if (pid == 0) // child process
			{
				//signal(SIGINT, handler);
			// Child will execv the command
			
			//setpgid(0, 0); only for backgrounded processes
				close(0);
				dup(pipeo2i[0]);
				close(1);
				dup(pipei2o[1]);
				
				execvp("bash", NULL);
				xmpp_debug(conn->ctx, "xmpp", "Bash terminated!");
				exit(0);
	     	}
		}
	}





    /* take a master jid and password on the command line */
    if(argc < 4){
        printf("Usage: xmppsh <MasterID> <Robot ID> <Password>\n \
                MasterID: The main@jabber.org use to send out the cmd\n \
                Robot ID: The bash@jabber.org use to receive the cmd\n \
                Password: The bash@jabber.org Password\n");
    }
    if (argc < 2) {        
        printf("MasterID:");
        scanf("%s", master);
        printf("Robot ID:");
        scanf("%s", jid);
        strcpy(pass, getpass("Password:"));
    }
    else if (argc == 2)
    {
        strcpy(master, argv[1]);
        
        //printf("MasterID:");
        //scanf("%s", master);
        printf("Robot ID:");
        scanf("%s", jid);
        strcpy(pass, getpass("Password:"));
    }
    else if(argc == 3)
    {
    	strcpy(master, argv[1]);
    	strcpy(jid, argv[2]);
        
        //printf("MasterID:");
        //scanf("%s", master);
        //printf("Robot ID:");
        //scanf("%s", jid);
        strcpy(pass, getpass("Password:"));
    }
    else
    {
		strcpy(master, argv[1]);
    	strcpy(jid, argv[2]);
		strcpy(pass, argv[3]);
        
        //printf("MasterID:");
        //scanf("%s", master);
        //printf("Robot ID:");
        //scanf("%s", jid);
        //strcpy(pass, getpass("Password:"));

    }
    

    /* init library */
    xmpp_initialize();

    /* create a context */
    if (DEBUGMOD)
    {
    	log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); /* pass NULL instead to silence output */
    }
    else
    {
    	log = NULL;
    }
    
    ctx = xmpp_ctx_new(NULL, log);

    /* create a connection */
    conn = xmpp_conn_new(ctx);

    /* setup authentication information */
    xmpp_conn_set_jid(conn, jid);
    xmpp_conn_set_pass(conn, pass);

    /* initiate connection */
    xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);

    /* enter the event loop - 
       our connect handler will trigger an exit */
    //xmpp_run(ctx);
    ctx->loop_status = XMPP_LOOP_RUNNING;
    while (ctx->loop_status == XMPP_LOOP_RUNNING) {
		xmpp_run_once(ctx, 1);
		sleep(1);
    }

    /* release our connection and context */
    xmpp_conn_release(conn);
    xmpp_ctx_free(ctx);

	kill(-pid, SIGINT);
	write(pipeo2i[1], "exit", 4);
	write(pipeo2i[1], "\n", 1);

    /* final shutdown of the library */
    xmpp_shutdown();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x0, 0x16420(%rip)     # 0x19270
jne 0x2f28
leaq 0x1644b(%rip), %rdi     # 0x192a8
callq 0x22f0
leaq 0x16447(%rip), %rdi     # 0x192b0
callq 0x22f0
movl 0x1643c(%rip), %edi     # 0x192b0
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x20b0
movl $0x1, %edi
callq 0x2420
movl %eax, 0x16423(%rip)     # 0x192b8
xorl %edi, %edi
callq 0x2420
movl %eax, 0x1641a(%rip)     # 0x192bc
movl $0x1, 0x163c4(%rip)     # 0x19270
callq 0x2370
movl %eax, 0x16409(%rip)     # 0x192c0
cmpl $0x0, 0x16402(%rip)     # 0x192c0
jl 0x2f26
cmpl $0x0, 0x163f9(%rip)     # 0x192c0
jne 0x2f24
xorl %edi, %edi
callq 0x20f0
movl 0x163d2(%rip), %edi     # 0x192a8
callq 0x2420
movl $0x1, %edi
callq 0x20f0
movl 0x163c9(%rip), %edi     # 0x192b4
callq 0x2420
leaq 0x11250(%rip), %rdi     # 0x14147
xorl %eax, %eax
movl %eax, %esi
callq 0x2380
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1113a(%rip), %rsi     # 0x14049
leaq 0x11236(%rip), %rdx     # 0x1414c
movb $0x0, %al
callq 0x6a80
xorl %edi, %edi
callq 0x2240
jmp 0x2f26
jmp 0x2f28
cmpl $0x4, -0x8(%rbp)
jge 0x2f3c
leaq 0x11228(%rip), %rdi     # 0x1415d
movb $0x0, %al
callq 0x2030
cmpl $0x2, -0x8(%rbp)
jge 0x2faa
leaq 0x11309(%rip), %rdi     # 0x14252
movb $0x0, %al
callq 0x2030
leaq 0x11b34(%rip), %rdi     # 0x14a8b
leaq 0x16322(%rip), %rsi     # 0x19280
movb $0x0, %al
callq 0x22a0
leaq 0x112f0(%rip), %rdi     # 0x1425c
movb $0x0, %al
callq 0x2030
leaq -0x40(%rbp), %rsi
leaq 0x11b0d(%rip), %rdi     # 0x14a8b
movb $0x0, %al
callq 0x22a0
leaq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq 0x112d2(%rip), %rdi     # 0x14266
callq 0x2270
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
jmp 0x3090
cmpl $0x2, -0x8(%rbp)
jne 0x3009
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x162c1(%rip), %rdi     # 0x19280
callq 0x2190
leaq 0x11291(%rip), %rdi     # 0x1425c
movb $0x0, %al
callq 0x2030
leaq -0x40(%rbp), %rsi
leaq 0x11aae(%rip), %rdi     # 0x14a8b
movb $0x0, %al
callq 0x22a0
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq 0x11273(%rip), %rdi     # 0x14266
callq 0x2270
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
jmp 0x308e
cmpl $0x3, -0x8(%rbp)
jne 0x3056
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x16262(%rip), %rdi     # 0x19280
callq 0x2190
leaq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2190
leaq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0x11223(%rip), %rdi     # 0x14266
callq 0x2270
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x2190
jmp 0x308c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1621b(%rip), %rdi     # 0x19280
callq 0x2190
leaq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2190
leaq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2190
jmp 0x308e
jmp 0x3090
callq 0x6590
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x6b20
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5060
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5a40
movq -0x20(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5ac0
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %r8
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
leaq -0x3da(%rip), %rcx      # 0x2d10
callq 0x5b40
movq -0x18(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x311e
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x6c70
movl $0x1, %edi
callq 0x23e0
jmp 0x30fa
movq -0x20(%rbp), %rdi
callq 0x5650
movq -0x18(%rbp), %rdi
callq 0x6be0
xorl %edi, %edi
subl 0x16188(%rip), %edi     # 0x192c0
movl $0x2, %esi
callq 0x2300
movl 0x16164(%rip), %edi     # 0x192ac
leaq 0x10f3d(%rip), %rsi     # 0x1408c
movl $0x4, %edx
callq 0x23a0
movl 0x1614d(%rip), %edi     # 0x192ac
leaq 0x10f24(%rip), %rsi     # 0x1408a
movl $0x1, %edx
callq 0x23a0
callq 0x65a0
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq