#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*/ close(int);
scalar_t__ memchr(char *, char, size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ trim(char **, size_t *);
int /*<<< orphan*/ write(int, char *, size_t);
int echo0(char *args, size_t length) {
  char *string;
  size_t strlength;
  int close_at_end;
  int fd;
  char *gt = (char *)memchr(args, '>', length);
  string = args;
  if (gt == NULL) {
    close_at_end = 0;
    fd = 1;
    strlength = length;
  } else {
    strlength = gt - args;
    length -= gt - args;
    gt++;
    length--;
    trim(&gt, &length);
    if (length > 0 && *gt == '#') {
      gt++;
      length--;
      sscanf(gt, "%d", &fd);
      fd += 100;
      close_at_end = 0;
    } else {
      char filename[255];
      memcpy(filename, gt, length);
      filename[length] = '\0';
      fd = open(filename, O_WRONLY);
      if (fd < 0)
        return fd;
      close_at_end = !0;
    }
  }
  trim(&string, &strlength);
  write(fd, string, strlength);
  if (close_at_end)
    close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<echo0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3e,%esi
call   1060 <memchr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c7 <echo0+0x57>
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12c6 <echo0+0x156>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <trim@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    126d <echo0+0xfd>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    126d <echo0+0xfd>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdb1(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x30(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    12c1 <echo0+0x151>
lea    -0x140(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,-0x140(%rbp,%rax,1)
lea    -0x140(%rbp),%rdi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12ba <echo0+0x14a>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12fc <echo0+0x18c>
movl   $0x1,-0x2c(%rbp)
jmp    12c6 <echo0+0x156>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <trim@plt>
mov    -0x30(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <write@plt>
cmpl   $0x0,-0x2c(%rbp)
je     12f5 <echo0+0x185>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo0>:
push   %r14
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x3e,%esi
mov    %r14,%rdx
call   1060 <memchr@plt>
mov    %rbx,0x8(%rsp)
test   %rax,%rax
je     127f <echo0+0x10f>
mov    %rax,%rcx
sub    %rbx,%rcx
mov    %rcx,(%rsp)
sub    %rax,%rbx
add    $0x1,%rax
mov    %rax,0x18(%rsp)
lea    (%rbx,%r14,1),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x10(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <trim@plt>
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rsi
test   %rdx,%rdx
je     122b <echo0+0xbb>
cmpb   $0x23,(%rsi)
jne    122b <echo0+0xbb>
add    $0x1,%rsi
mov    %rsi,0x18(%rsp)
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x10(%rsp)
lea    0xe06(%rip),%rax
lea    0x20(%rsp),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
call   1080 <sscanf@plt>
addl   $0x64,0x20(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <trim@plt>
mov    0x20(%rsp),%edi
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
jmp    129e <echo0+0x12e>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <memcpy@plt>
mov    0x10(%rsp),%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     12a5 <echo0+0x135>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <trim@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %ebx,%edi
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
jmp    12a3 <echo0+0x133>
mov    %r14,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <trim@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    $0x1,%edi
call   1030 <write@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
define i32 @echo0(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [255 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i64 @memchr(i8* %12, i8 signext 62, i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %10
%16 = load i8*, i8** %4
store i8* %16, i8** %6
%17 = load i8*, i8** %10
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
store i32 0, i32* %8
store i32 1, i32* %9
%20 = load i64, i64* %5
store i64 %20, i64* %7
br label %71
21: ; preds = %2
%22 = load i8*, i8** %10
%23 = load i8*, i8** %4
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
store i64 %26, i64* %7
%27 = load i8*, i8** %10
%28 = load i8*, i8** %4
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = load i64, i64* %5
%33 = sub i64 %32, %31
store i64 %33, i64* %5
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %10
%36 = load i64, i64* %5
%37 = add i64 %36, -1
store i64 %37, i64* %5
%38 = call i32 @trim(i8** %10, i64* %5)
%39 = load i64, i64* %5
%40 = icmp ugt i64 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %21
%42 = load i8*, i8** %10
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 35
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = load i8*, i8** %10
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %10
%49 = load i64, i64* %5
%50 = add i64 %49, -1
store i64 %50, i64* %5
%51 = load i8*, i8** %10
%52 = call i32 @sscanf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 100
store i32 %54, i32* %9
store i32 0, i32* %8
br label %70
55: ; preds = %41, %21
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%57 = load i8*, i8** %10
%58 = load i64, i64* %5
%59 = call i32 @memcpy(i8* %56, i8* %57, i64 %58)
%60 = load i64, i64* %5
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%63 = load i32, i32* @O_WRONLY
%64 = call i32 @open(i8* %62, i32 %63)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = load i32, i32* %9
store i32 %68, i32* %3
br label %83
69: ; preds = %55
store i32 1, i32* %8
br label %70
70: ; preds = %69, %46
br label %71
71: ; preds = %70, %19
%72 = call i32 @trim(i8** %6, i64* %7)
%73 = load i32, i32* %9
%74 = load i8*, i8** %6
%75 = load i64, i64* %7
%76 = call i32 @write(i32 %73, i8* %74, i64 %75)
%77 = load i32, i32* %8
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %71
%80 = load i32, i32* %9
%81 = call i32 @close(i32 %80)
br label %82
82: ; preds = %79, %71
store i32 0, i32* %3
br label %83
83: ; preds = %82, %67
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
define i32 @echo0(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [255 x i8]
%9 = bitcast i8** %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i8** %7 to i8*
%13 = tail call i64 @memchr(i8* %0, i8 signext 62, i64 %1)
store i8* %0, i8** %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
store i64 %1, i64* %5
%16 = call i32 @trim(i8** %4, i64* %5)
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = call i32 @write(i32 1, i8* %17, i64 %18)
br label %60
20: ; preds = %2
%21 = inttoptr i64 %13 to i8*
%22 = ptrtoint i8* %0 to i64
%23 = sub i64 %13, %22
store i64 %23, i64* %5
%24 = sub i64 %22, %13
%25 = add i64 %24, %1
%26 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %26, i8** %7
%27 = add i64 %25, -1
store i64 %27, i64* %3
%28 = call i32 @trim(i8** %7, i64* %3)
%29 = load i64, i64* %3
%30 = icmp eq i64 %29, 0
%31 = load i8*, i8** %7
br i1 %30, label %46, label %32
32: ; preds = %20
%33 = load i8, i8* %31
%34 = icmp eq i8 %33, 35
br i1 %34, label %35, label %46
35: ; preds = %32
%36 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %36, i8** %7
%37 = add i64 %29, -1
store i64 %37, i64* %3
%38 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 100
store i32 %40, i32* %6
%41 = call i32 @trim(i8** %4, i64* %5)
%42 = load i32, i32* %6
%43 = load i8*, i8** %4
%44 = load i64, i64* %5
%45 = call i32 @write(i32 %42, i8* %43, i64 %44)
br label %60
46: ; preds = %20, %32
%47 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%48 = call i32 @memcpy(i8* %47, i8* %31, i64 %29)
%49 = load i64, i64* %3
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* @O_WRONLY
%52 = call i32 @open(i8* %47, i32 %51)
%53 = icmp slt i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %46
%55 = call i32 @trim(i8** %4, i64* %5)
%56 = load i8*, i8** %4
%57 = load i64, i64* %5
%58 = call i32 @write(i32 %52, i8* %56, i64 %57)
%59 = call i32 @close(i32 %52)
br label %60
60: ; preds = %54, %35, %15, %46
%61 = phi i32 [ %52, %46 ], [ 0, %15 ], [ 0, %35 ], [ 0, %54 ]
ret i32 %61
}