#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fork();
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int /*<<< orphan*/ wait(int);
int main(int argc, char *argv[]) {
  char *buffer = malloc(sizeof(char) * 141);
  int k;
  pid_t pid;
  while (1) {
    pid = fork();
    char *args[4];
    if (pid == 0) {
      fgets(buffer, 140, stdin);
      buffer[strlen(buffer)] = '\0';
      args[0] = "./twitsay";
      args[1] = "localhost";
      args[2] = "3331";
      args[3] = buffer;
      execv("./twitsay", args);
    } else if (pid == -1) {
      perror("error");
    } else if (pid > 0) {
      wait(pid);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x8d,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1219 <main+0xa9>
mov    -0x18(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    $0x8c,%esi
call   1040 <fgets@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0xe1e(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe1d(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe1c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1080 <execv@plt>
jmp    1250 <main+0xe0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1234 <main+0xc4>
lea    0xdef(%rip),%rdi
call   1060 <perror@plt>
jmp    124b <main+0xdb>
cmpl   $0x0,-0x20(%rbp)
jle    1246 <main+0xd6>
mov    -0x20(%rbp),%edi
call   1070 <wait@plt>
jmp    124b <main+0xdb>
jmp    1250 <main+0xe0>
jmp    1194 <main+0x24>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x8d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    0x2e56(%rip),%r13
lea    0xe67(%rip),%r14
lea    0xe6a(%rip),%rbp
lea    0xe6d(%rip),%r12
mov    %rsp,%r15
jmp    11eb <main+0x7b>
nopl   0x0(%rax)
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x8c,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %r14,(%rsp)
mov    %rbp,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <execv@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11b0 <main+0x40>
cmp    $0xffffffff,%eax
je     1208 <main+0x98>
test   %eax,%eax
jle    11eb <main+0x7b>
mov    %eax,%edi
call   1070 <wait@plt>
jmp    11eb <main+0x7b>
lea    0xe0a(%rip),%rdi
call   1060 <perror@plt>
jmp    11eb <main+0x7b>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [10 x i8] c"./twitsay\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"3331\00"
@.str.3 = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @malloc(i32 141)
store i8* %10, i8** %6
br label %11
11: ; preds = %2, %43
%12 = call i32 (...) @fork()
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 140, i32 %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %25
%26 = load i8*, i8** %6
%27 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 3
store i8* %26, i8** %27
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
%29 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %28)
br label %43
30: ; preds = %11
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %42
35: ; preds = %30
%36 = load i32, i32* %8
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* %8
%40 = call i32 @wait(i32 %39)
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41, %33
br label %43
43: ; preds = %42, %15
br label %11
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [10 x i8] c"./twitsay\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"3331\00"
@.str.3 = [6 x i8] c"error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x i8*]
%4 = tail call dereferenceable_or_null(141) i8* @malloc(i32 141)
%5 = bitcast [4 x i8*]* %3 to i8*
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%9 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 3
br label %10
10: ; preds = %24, %2
%11 = call i32 (...) @fork()
switch i32 %11, label %20 [
i32 0, label %12
i32 -1, label %18
]
12: ; preds = %10
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %4, i32 140, i32 %13)
%15 = call i64 @strlen(i8* dereferenceable(1) %4)
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 0, i8* %16
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %8
store i8* %4, i8** %9
%17 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6)
br label %24
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %24
20: ; preds = %10
%21 = icmp sgt i32 %11, 0
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = call i32 @wait(i32 %11)
br label %24
24: ; preds = %18, %22, %20, %12
br label %10
}