#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
FILE *open_output(int argc, char *argv[]) {
  FILE *out;
  if (argc < 2) {
    fputs("No output device specified\n", stderr);
    return NULL;
  }
  out = fopen(argv[1], "w");
  if (out == NULL) {
    perror("fopen");
    exit(349);
  }
  fputs("\nReading from /dev/ttyS0:\n\n", out);
  return out;
}


x86 assembly (clang, -O0):
<open_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    117c <open_output+0x3c>
mov    0x2e80(%rip),%rax
mov    (%rax),%rsi
lea    0xe96(%rip),%rdi
call   1030 <fputs@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <open_output+0x8d>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe91(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <open_output+0x75>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
mov    $0x15d,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_output>:
push   %rbx
cmp    $0x1,%edi
jg     116a <open_output+0x2a>
mov    0x2e93(%rip),%rax
mov    (%rax),%rcx
lea    0xea9(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
xor    %ebx,%ebx
jmp    119b <open_output+0x5b>
mov    0x8(%rsi),%rdi
lea    0xea7(%rip),%rsi
call   1030 <fopen@plt>
test   %rax,%rax
je     11a0 <open_output+0x60>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rax
pop    %rbx
ret
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
mov    $0x15d,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"No output device specified\0A\00"
@stderr = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [28 x i8] c"\0AReading from /dev/ttyS0:\0A\0A\00"
define i32* @open_output(i32 %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32*, i32** @stderr
%11 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32* %10)
store i32* null, i32** %3
br label %26
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 349)
unreachable
22: ; preds = %12
%23 = load i32*, i32** %6
%24 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32* %23)
%25 = load i32*, i32** %6
store i32* %25, i32** %3
br label %26
26: ; preds = %22, %9
%27 = load i32*, i32** %3
ret i32* %27
}

LLVM IR (-O2):
@.str = [28 x i8] c"No output device specified\0A\00"
@stderr = global i32* null
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [28 x i8] c"\0AReading from /dev/ttyS0:\0A\0A\00"
define noalias i32* @open_output(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 27, i64 1, i32* %5)
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 349)
unreachable
15: ; preds = %7
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i64 27, i64 1, i32* %10)
br label %17
17: ; preds = %15, %4
%18 = phi i32* [ null, %4 ], [ %10, %15 ]
ret i32* %18
}