#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 STDIN_FILENO;
int /*<<< orphan*/ fsync(int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 2)
    return -1;
  char *text = argv[1];
  int output = STDIN_FILENO;
  int result = 0;
  result = write(output, text, strlen(text));
  if (result < 0)
    return -1;
  fsync(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    115c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <main+0x98>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11b9 <main+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c8 <main+0x98>
mov    -0x1c(%rbp),%edi
call   1050 <fsync@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     116f <main+0x3f>
mov    0x8(%rsi),%rbp
mov    0x2e97(%rip),%rax
mov    (%rax),%r14d
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     116f <main+0x3f>
mov    %r14d,%edi
call   1050 <fsync@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %28
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %6
%16 = load i32, i32* @STDIN_FILENO
store i32 %16, i32* %7
store i32 0, i32* %8
%17 = load i32, i32* %7
%18 = load i8*, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 -1, i32* %3
br label %28
25: ; preds = %12
%26 = load i32, i32* %7
%27 = call i32 @fsync(i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %25, %24, %11
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @STDIN_FILENO
%8 = tail call i32 @strlen(i8* %6)
%9 = tail call i32 @write(i32 %7, i8* %6, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @fsync(i32 %7)
br label %13
13: ; preds = %11, %4, %2
%14 = phi i32 [ -1, %2 ], [ 0, %11 ], [ -1, %4 ]
ret i32 %14
}