#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*/ bzero(char *, int);
int /*<<< orphan*/ d_close(int);
int d_open(char *, char *, char *);
int d_write(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd, rc;
  char buffer[1024] = "", maquina_y_puerto[255] = "", ruta[255] = "", *entorno;
  if (argc != 2) {
    printf("%s", "Uso: dtac ruta\n");
    return -1;
  }
  if ((entorno = getenv("DSERVER")) == NULL)
    fprintf(stderr, "Variable de entorno DSERVER no definida\n");
  strncpy(maquina_y_puerto, entorno, strlen(entorno));
  if (sscanf(argv[1], "%s", ruta) != 1) {
    printf("%s", "Uso: dtac ruta\n");
    return -1;
  }
  fd = d_open(maquina_y_puerto, ruta, "w+");
  if (fd == -1)
    return -1;
  printf(":q para terminar\n");
  while (1) {
    bzero(buffer, 1024);
    fgets(buffer, 1024, stdin);
    if (strcmp(buffer, ":q\n") == 0)
      break;
    rc = d_write(fd, buffer, strlen(buffer));
    (void)rc;
  }
  d_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x520(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <memset@plt>
lea    -0x620(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     124d <main+0x7d>
lea    0xdcd(%rip),%rdi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13dd <main+0x20d>
lea    0xdbf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x628(%rbp)
cmp    $0x0,%rax
jne    127f <main+0xaf>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
call   10a0 <fprintf@plt>
lea    -0x520(%rbp),%rax
mov    %rax,-0x638(%rbp)
mov    -0x628(%rbp),%rax
mov    %rax,-0x630(%rbp)
mov    -0x628(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x638(%rbp),%rdi
mov    -0x630(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x620(%rbp),%rdx
lea    0xd2e(%rip),%rsi
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
je     1301 <main+0x131>
lea    0xd19(%rip),%rdi
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13dd <main+0x20d>
lea    -0x520(%rbp),%rdi
lea    -0x620(%rbp),%rsi
lea    0xd2e(%rip),%rdx
call   10f0 <d_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1334 <main+0x164>
movl   $0xffffffff,-0x4(%rbp)
jmp    13dd <main+0x20d>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    -0x420(%rbp),%rdi
mov    0x2c87(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xcde(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    138f <main+0x1bf>
jmp    13ce <main+0x1fe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x644(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x640(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x644(%rbp),%edi
mov    -0x640(%rbp),%rsi
mov    %eax,%edx
call   10b0 <d_write@plt>
mov    %eax,-0x18(%rbp)
jmp    1342 <main+0x172>
mov    -0x14(%rbp),%edi
call   10e0 <d_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x608,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x200(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x1ef(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x2,%ebp
jne    141c <main+0x24c>
lea    0xd13(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1312 <main+0x142>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x100(%rsp),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    0x8(%rbx),%rdi
lea    0xcc9(%rip),%rsi
mov    %rsp,%rdx
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
jne    141c <main+0x24c>
lea    0xce5(%rip),%rdx
lea    0x100(%rsp),%rdi
mov    %rsp,%rsi
call   10f0 <d_open@plt>
cmp    $0xffffffff,%eax
je     1428 <main+0x258>
mov    %eax,%ebx
lea    0xcca(%rip),%rdi
call   1050 <puts@plt>
lea    0x200(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
mov    0x2c56(%rip),%r15
mov    (%r15),%edx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    0xc8e(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1411 <main+0x241>
lea    0x200(%rsp),%rbp
lea    0xc72(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   10b0 <d_write@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
mov    (%r15),%edx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    13d0 <main+0x200>
mov    %ebx,%edi
call   10e0 <d_close@plt>
xor    %eax,%eax
jmp    142d <main+0x25d>
lea    0xc29(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x608,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [16 x i8] c"Uso: dtac ruta\0A\00"
@.str.2 = [8 x i8] c"DSERVER\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Variable de entorno DSERVER no definida\0A\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [18 x i8] c":q para terminar\0A\00"
@stdin = global i32 0
@.str.6 = [4 x i8] c":q\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca [255 x i8]
%10 = alloca [255 x i8]
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [1024 x i8]* %8 to i8*
%13 = bitcast [255 x i8]* %9 to i8*
%14 = bitcast [255 x i8]* %10 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
19: ; preds = %2
%20 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %11
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %11
%28 = load i8*, i8** %11
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @strncpy(i8* %26, i8* %27, i32 %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %68
39: ; preds = %25
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%42 = call i32 @d_open(i8* %40, i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 -1, i32* %3
br label %68
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %58
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i32 @bzero(i8* %49, i32 1024)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* @stdin
%53 = call i32 @fgets(i8* %51, i32 1024, i32 %52)
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %48
br label %65
58: ; preds = %48
%59 = load i32, i32* %6
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = call i32 @d_write(i32 %59, i8* %60, i32 %62)
store i32 %63, i32* %7
%64 = load i32, i32* %7
br label %48
65: ; preds = %57
%66 = load i32, i32* %6
%67 = call i32 @d_close(i32 %66)
store i32 0, i32* %3
br label %68
68: ; preds = %65, %45, %37, %17
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [8 x i8] c"DSERVER\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Variable de entorno DSERVER no definida\0A\00"
@.str.4 = [3 x i8] c"w+\00"
@stdin = global i32 0
@.str.6 = [4 x i8] c":q\0A\00"
@str = [17 x i8] c":q para terminar\00"
@str.8 = [15 x i8] c"Uso: dtac ruta\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %47
12: ; preds = %2
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %15, %12
%19 = tail call i32 @strlen(i8* %13)
%20 = call i32 @strncpy(i8* %7, i8* %13, i32 %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%24 = icmp eq i32 %23, 1
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %47
27: ; preds = %18
%28 = call i32 @d_open(i8* %7, i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i32 %28, -1
br i1 %29, label %47, label %30
30: ; preds = %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%32 = call i32 @bzero(i8* %6, i32 1024)
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %6, i32 1024, i32 %33)
%35 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %30, %37
%38 = call i32 @strlen(i8* %6)
%39 = call i32 @d_write(i32 %28, i8* %6, i32 %38)
%40 = call i32 @bzero(i8* %6, i32 1024)
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %6, i32 1024, i32 %41)
%43 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %37
45: ; preds = %37, %30
%46 = call i32 @d_close(i32 %28)
br label %47
47: ; preds = %27, %45, %25, %10
%48 = phi i32 [ -1, %10 ], [ -1, %25 ], [ 0, %45 ], [ -1, %27 ]
ret i32 %48
}