#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*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Por favor introduce el nombre del fifo");
    exit(1);
  }
  int fd;
  if ((fd = open(argv[1], O_WRONLY)) < 0) {
    perror("Error abriendo el archivo fifo");
    exit(1);
  }
  while (1 == 1) {
    int dato;
    char cadena[1];
    scanf("%s", cadena);
    sscanf(cadena, "%d", &dato);
    if (dato == 0) {
      write(fd, &dato, sizeof(int));
      exit(0);
    } else {
      write(fd, &dato, sizeof(int));
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x36>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11de <main+0x6e>
lea    0xe58(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e3 <main+0x73>
lea    -0x19(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x19(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1229 <main+0xb9>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    11e3 <main+0x73>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11ad <main+0x3d>
mov    0x8(%rsi),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
jns    11c3 <main+0x53>
lea    0xe89(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %eax,%r15d
lea    0xe79(%rip),%rdi
lea    0xb(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe68(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1240 <main+0xd0>
lea    0xc(%rsp),%rbx
lea    0xe45(%rip),%r14
lea    0xb(%rsp),%rbp
lea    0xe3c(%rip),%r12
nopl   (%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
jne    1210 <main+0xa0>
lea    0xc(%rsp),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Por favor introduce el nombre del fifo\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"Error abriendo el archivo fifo\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"%d\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 [1 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
br label %25
25: ; preds = %24, %39
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i32, i32* %6
%34 = call i32 @write(i32 %33, i32* %7, i32 4)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %25
%37 = load i32, i32* %6
%38 = call i32 @write(i32 %37, i32* %7, i32 4)
br label %39
39: ; preds = %36
br label %25
}

LLVM IR (-O2):
@.str = [39 x i8] c"Por favor introduce el nombre del fifo\00"
@O_WRONLY = global i32 0
@.str.1 = [31 x i8] c"Error abriendo el archivo fifo\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %9
%16 = bitcast i32* %3 to i8*
%17 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %28
22: ; preds = %9
%23 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %28, %15
%26 = call i32 @write(i32 %13, i32* %3, i32 4)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %15, %28
%29 = call i32 @write(i32 %13, i32* %3, i32 4)
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%31 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 0
br i1 %33, label %25, label %28
}