int main(int ac, char **av, char **env) {
  (void)ac;
  (void)av;
  (void)env;
  int pid = getpid();
  int tid = gettid();
  printf("printf: test module runs with pid %d tid %d\n", pid, tid);
  char buf[1024];
  snprintf(buf, sizeof(buf), "syslog: test module runs with pid %d tid %d", pid,
           tid);
  ssyslog(0, buf);
  int tcpfd = open("tcp://213.180.204.8:80", 0, 0);
  printf("tcp fd = %d\n", tcpfd);
  write(tcpfd, "GET /\n", sizeof("GET /\n"));
  sleepmsec(4000);
  read(tcpfd, buf, 512);
  buf[512] = 0;
  printf("ya.ru: '%s'\n", buf);
  close(tcpfd);
  while (1) {
    ssyslog(0, "module test is running");
    sleepmsec(4000);
  }
  exit(0);
  asm("int $3");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    $0x400,%esi
lea    0xe2e(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rsi
xor    %edi,%edi
mov    $0x0,%al
call   1080 <ssyslog@plt>
lea    0xe3c(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x424(%rbp),%edi
lea    0xe2e(%rip),%rsi
mov    $0x7,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    $0xfa0,%edi
mov    $0x0,%al
call   10c0 <sleepmsec@plt>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   10a0 <read@plt>
movb   $0x0,-0x220(%rbp)
lea    -0x420(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x424(%rbp),%edi
mov    $0x0,%al
call   1090 <close@plt>
xor    %edi,%edi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1080 <ssyslog@plt>
mov    $0xfa0,%edi
mov    $0x0,%al
call   10c0 <sleepmsec@plt>
jmp    12a9 <main+0x109>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <gettid@plt>
mov    %eax,%ebx
lea    0xe3c(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe57(%rip),%rdx
mov    %rsp,%r14
mov    $0x400,%esi
mov    %r14,%rdi
mov    %ebp,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1070 <snprintf@plt>
xor    %edi,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <ssyslog@plt>
lea    0xe59(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   10b0 <open@plt>
mov    %eax,%ebp
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe59(%rip),%rsi
mov    $0x7,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <write@plt>
mov    $0xfa0,%edi
xor    %eax,%eax
call   10c0 <sleepmsec@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   10a0 <read@plt>
movb   $0x0,0x200(%rsp)
lea    0xe26(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <close@plt>
lea    0xe19(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <ssyslog@plt>
mov    $0xfa0,%edi
xor    %eax,%eax
call   10c0 <sleepmsec@plt>
jmp    1280 <main+0xe0>

LLVM IR (-O0):
@.str = [45 x i8] c"printf: test module runs with pid %d tid %d\0A\00"
@.str.1 = [44 x i8] c"syslog: test module runs with pid %d tid %d\00"
@.str.2 = [23 x i8] c"tcp://213.180.204.8:80\00"
@.str.3 = [13 x i8] c"tcp fd = %d\0A\00"
@.str.4 = [7 x i8] c"GET /\0A\00"
@.str.5 = [13 x i8] c"ya.ru: '%s'\0A\00"
@.str.6 = [23 x i8] c"module test is running\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%12 = load i32, i32* %5
%13 = load i8**, i8*** %6
%14 = load i8**, i8*** %7
%15 = call i32 (...) @getpid()
store i32 %15, i32* %8
%16 = call i32 (...) @gettid()
store i32 %16, i32* %9
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %20, i64 1024, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%25 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @ssyslog to i32 (i32, i8*, ...)*)(i32 0, i8* %24)
%26 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %11
%30 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 7)
%31 = call i32 (i32, ...) bitcast (i32 (...)* @sleepmsec to i32 (i32, ...)*)(i32 4000)
%32 = load i32, i32* %11
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%34 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %32, i8* %33, i32 512)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 512
store i8 0, i8* %35
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %11
%39 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %38)
br label %40
40: ; preds = %3, %40
%41 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @ssyslog to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 (i32, ...) bitcast (i32 (...)* @sleepmsec to i32 (i32, ...)*)(i32 4000)
br label %40
}

LLVM IR (-O2):
@.str = [45 x i8] c"printf: test module runs with pid %d tid %d\0A\00"
@.str.1 = [44 x i8] c"syslog: test module runs with pid %d tid %d\00"
@.str.2 = [23 x i8] c"tcp://213.180.204.8:80\00"
@.str.3 = [13 x i8] c"tcp fd = %d\0A\00"
@.str.4 = [7 x i8] c"GET /\0A\00"
@.str.5 = [13 x i8] c"ya.ru: '%s'\0A\00"
@.str.6 = [23 x i8] c"module test is running\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [1024 x i8]
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (...) @gettid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %8, i64 1024, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %6)
%10 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @ssyslog to i32 (i32, i8*, ...)*)(i32 0, i8* %8)
%11 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 7)
%14 = call i32 (i32, ...) bitcast (i32 (...)* @sleepmsec to i32 (i32, ...)*)(i32 4000)
%15 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %11, i8* %8, i32 512)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 512
store i8 0, i8* %16
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%18 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %11)
br label %19
19: ; preds = %19, %3
%20 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @ssyslog to i32 (i32, i8*, ...)*)(i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 (i32, ...) bitcast (i32 (...)* @sleepmsec to i32 (i32, ...)*)(i32 4000)
br label %19
}