#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*/ Display;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *);
int open(char *, int /*<<< orphan*/);
int open_serial(char *);
int /*<<< orphan*/ read_barcode(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ write(int, char *, int);
void child_barcode(int pipe_to_parent) {
  Display *disp;
  int serial_fd;
  serial_fd = open("/dev/ttyUSB0", O_RDONLY);
  if ((serial_fd == -1) && (errno == ENOENT)) {
    serial_fd = open_serial("/dev/ttyS0");
  } else {
    close(serial_fd);
    serial_fd = open_serial("/dev/ttyUSB0");
  }
  disp = XOpenDisplay(NULL);
  if (!disp)
    fatal("Can't open display");
  write(pipe_to_parent, "OK", 1);
  read_barcode(disp, serial_fd, pipe_to_parent);
}


x86 assembly (clang, -O0):
<child_barcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cb <child_barcode+0x5b>
mov    0x2e34(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
jne    11cb <child_barcode+0x5b>
lea    0xe4f(%rip),%rdi
call   1060 <open_serial@plt>
mov    %eax,-0x14(%rbp)
jmp    11e2 <child_barcode+0x72>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
lea    0xe26(%rip),%rdi
call   1060 <open_serial@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1206 <child_barcode+0x96>
lea    0xe17(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x4(%rbp),%edi
lea    0xe1b(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1090 <read_barcode@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<child_barcode>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rbp
mov    %rbp,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    11b3 <child_barcode+0x43>
mov    0x2e3d(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e23(%rip),%rdx
cmp    (%rdx),%rcx
jne    11b3 <child_barcode+0x43>
lea    0xe5c(%rip),%rbp
jmp    11ba <child_barcode+0x4a>
mov    %eax,%edi
call   1040 <close@plt>
mov    %rbp,%rdi
call   1060 <open_serial@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11df <child_barcode+0x6f>
lea    0xe3e(%rip),%rdi
call   1080 <fatal@plt>
lea    0xe45(%rip),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <read_barcode@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.2 = [19 x i8] c"Can't open display\00"
@.str.3 = [3 x i8] c"OK\00"
define void @child_barcode(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @open_serial(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %4
br label %19
15: ; preds = %9, %1
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = call i32 @open_serial(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %4
br label %19
19: ; preds = %15, %13
%20 = call i32* @XOpenDisplay(i32* null)
store i32* %20, i32** %3
%21 = load i32*, i32** %3
%22 = icmp ne i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %2
%27 = call i32 @write(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1)
%28 = load i32*, i32** %3
%29 = load i32, i32* %4
%30 = load i32, i32* %2
%31 = call i32 @read_barcode(i32* %28, i32 %29, i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@.str.2 = [19 x i8] c"Can't open display\00"
@.str.3 = [3 x i8] c"OK\00"
define void @child_barcode(i32 %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOENT
%8 = icmp eq i64 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5, %1
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %5, %9
%12 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %5 ]
%13 = tail call i32 @open_serial(i8* %12)
%14 = tail call i32* @XOpenDisplay(i32* null)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1)
%20 = tail call i32 @read_barcode(i32* %14, i32 %13, i32 %0)
ret void
}