#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 */
struct termios {
  int c_cflag;
  int c_iflag;
  int c_lflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int /*<<< orphan*/ B1200;
int CLOCAL;
int CREAD;
int CS7;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ICRNL;
int INPCK;
int ISIG;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int open(char const *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int teleinfo_open(const char *port) {
  struct termios teleinfo_serial_attr;
  int fd;
  if ((fd = open(port, O_RDWR | O_NOCTTY)) == -1) {
    syslog(LOG_ERR, "Erreur ouverture du port serie %s !", port);
    return 0;
  }
  tcgetattr(fd, &teleinfo_serial_attr);
  cfsetispeed(&teleinfo_serial_attr, B1200);
  cfsetospeed(&teleinfo_serial_attr, B1200);
  teleinfo_serial_attr.c_cflag |= (CLOCAL | CREAD);
  teleinfo_serial_attr.c_cflag |= PARENB;
  teleinfo_serial_attr.c_cflag &= ~PARODD;
  teleinfo_serial_attr.c_cflag &= ~CSTOPB;
  teleinfo_serial_attr.c_cflag &= ~CSIZE;
  teleinfo_serial_attr.c_cflag |= CS7;
  teleinfo_serial_attr.c_iflag |= (INPCK | ISTRIP);
  teleinfo_serial_attr.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL);
  teleinfo_serial_attr.c_oflag &= ~OPOST;
  teleinfo_serial_attr.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  teleinfo_serial_attr.c_cc[VTIME] = 80;
  teleinfo_serial_attr.c_cc[VMIN] = 0;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &teleinfo_serial_attr);
  return fd;
}


x86 assembly (clang, -O0):
<teleinfo_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    11c8 <teleinfo_open+0x58>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe49(%rip),%rsi
call   1050 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    133e <teleinfo_open+0x1ce>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    0x2d88(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    0x2cdc(%rip),%rcx
or     (%rcx),%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    0x2d4c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cdb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d42(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
mov    0x2ce5(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd4(%rip),%rcx
or     (%rcx),%eax
mov    0x2cbb(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c4d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x50,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c80(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x34(%rbp),%edi
mov    0x2c4c(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x34(%rbp),%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<teleinfo_open>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2e66(%rip),%rax
mov    0x2dd7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12d5 <teleinfo_open+0x165>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2d97(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d44(%rip),%rax
mov    0x2dbd(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2ddf(%rip),%rax
or     (%rax),%ecx
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    0x2d2d(%rip),%rdx
or     (%rdx),%eax
mov    0x2d84(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d0f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d46(%rip),%rcx
mov    0x2d37(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,(%rsp)
or     0x4(%rsp),%edx
mov    0x2d9d(%rip),%rax
mov    0x2da6(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d33(%rip),%rax
or     (%rax),%ecx
mov    0x2d9a(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %edx,%ecx
mov    %ecx,0x4(%rsp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x2cd2(%rip),%rax
mov    0x2d43(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d30(%rip),%rax
or     (%rax),%ecx
mov    0x2d17(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2cab(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x50,(%rax,%rcx,4)
mov    0x2ce2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <tcflush@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
jmp    12ef <teleinfo_open+0x17f>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
mov    %rbx,%rdx
call   1050 <syslog@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@LOG_ERR = global i32 0
@.str = [36 x i8] c"Erreur ouverture du port serie %s !\00"
@B1200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICRNL = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @teleinfo_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.termios
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_NOCTTY
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @LOG_ERR
%14 = load i8*, i8** %3
%15 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %100
16: ; preds = %1
%17 = load i32, i32* %5
%18 = call i32 @tcgetattr(i32 %17, %struct.termios* %4)
%19 = load i32, i32* @B1200
%20 = call i32 @cfsetispeed(%struct.termios* %4, i32 %19)
%21 = load i32, i32* @B1200
%22 = call i32 @cfsetospeed(%struct.termios* %4, i32 %21)
%23 = load i32, i32* @CLOCAL
%24 = load i32, i32* @CREAD
%25 = or i32 %23, %24
%26 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = or i32 %27, %25
store i32 %28, i32* %26
%29 = load i32, i32* @PARENB
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%31 = load i32, i32* %30
%32 = or i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @PARODD
%34 = xor i32 %33, -1
%35 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%36 = load i32, i32* %35
%37 = and i32 %36, %34
store i32 %37, i32* %35
%38 = load i32, i32* @CSTOPB
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @CSIZE
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @CS7
%49 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%50 = load i32, i32* %49
%51 = or i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @INPCK
%53 = load i32, i32* @ISTRIP
%54 = or i32 %52, %53
%55 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%56 = load i32, i32* %55
%57 = or i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @IXON
%59 = load i32, i32* @IXOFF
%60 = or i32 %58, %59
%61 = load i32, i32* @IXANY
%62 = or i32 %60, %61
%63 = load i32, i32* @ICRNL
%64 = or i32 %62, %63
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @OPOST
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 4
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @ICANON
%75 = load i32, i32* @ECHO
%76 = or i32 %74, %75
%77 = load i32, i32* @ECHOE
%78 = or i32 %76, %77
%79 = load i32, i32* @ISIG
%80 = or i32 %78, %79
%81 = xor i32 %80, -1
%82 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%83 = load i32, i32* %82
%84 = and i32 %83, %81
store i32 %84, i32* %82
%85 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%86 = load i32*, i32** %85
%87 = load i64, i64* @VTIME
%88 = getelementptr inbounds i32, i32* %86, i64 %87
store i32 80, i32* %88
%89 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%90 = load i32*, i32** %89
%91 = load i64, i64* @VMIN
%92 = getelementptr inbounds i32, i32* %90, i64 %91
store i32 0, i32* %92
%93 = load i32, i32* %5
%94 = load i32, i32* @TCIFLUSH
%95 = call i32 @tcflush(i32 %93, i32 %94)
%96 = load i32, i32* %5
%97 = load i32, i32* @TCSANOW
%98 = call i32 @tcsetattr(i32 %96, i32 %97, %struct.termios* %4)
%99 = load i32, i32* %5
store i32 %99, i32* %2
br label %100
100: ; preds = %16, %12
%101 = load i32, i32* %2
ret i32 %101
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@LOG_ERR = global i32 0
@.str = [36 x i8] c"Erreur ouverture du port serie %s !\00"
@B1200 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS7 = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@ICRNL = global i32 0
@OPOST = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @teleinfo_open(i8* %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @LOG_ERR
%11 = tail call i32 @syslog(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %76
12: ; preds = %1
%13 = call i32 @tcgetattr(i32 %7, %struct.termios* %2)
%14 = load i32, i32* @B1200
%15 = call i32 @cfsetispeed(%struct.termios* %2, i32 %14)
%16 = load i32, i32* @B1200
%17 = call i32 @cfsetospeed(%struct.termios* %2, i32 %16)
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @CREAD
%20 = or i32 %19, %18
%21 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %20, %22
%24 = load i32, i32* @PARENB
%25 = or i32 %24, %23
%26 = load i32, i32* @PARODD
%27 = load i32, i32* @CSTOPB
%28 = or i32 %26, %27
%29 = load i32, i32* @CSIZE
%30 = or i32 %28, %29
%31 = xor i32 %30, -1
%32 = and i32 %25, %31
%33 = load i32, i32* @CS7
%34 = or i32 %33, %32
store i32 %34, i32* %21
%35 = load i32, i32* @INPCK
%36 = load i32, i32* @ISTRIP
%37 = or i32 %36, %35
%38 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%39 = load i32, i32* %38
%40 = or i32 %37, %39
%41 = load i32, i32* @IXON
%42 = load i32, i32* @IXOFF
%43 = or i32 %42, %41
%44 = load i32, i32* @IXANY
%45 = or i32 %43, %44
%46 = load i32, i32* @ICRNL
%47 = or i32 %45, %46
%48 = xor i32 %47, -1
%49 = and i32 %40, %48
store i32 %49, i32* %38
%50 = load i32, i32* @OPOST
%51 = xor i32 %50, -1
%52 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%53 = load i32, i32* %52
%54 = and i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* @ICANON
%56 = load i32, i32* @ECHO
%57 = or i32 %56, %55
%58 = load i32, i32* @ECHOE
%59 = or i32 %57, %58
%60 = load i32, i32* @ISIG
%61 = or i32 %59, %60
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%67 = load i32*, i32** %66
%68 = load i64, i64* @VTIME
%69 = getelementptr inbounds i32, i32* %67, i64 %68
store i32 80, i32* %69
%70 = load i64, i64* @VMIN
%71 = getelementptr inbounds i32, i32* %67, i64 %70
store i32 0, i32* %71
%72 = load i32, i32* @TCIFLUSH
%73 = call i32 @tcflush(i32 %7, i32 %72)
%74 = load i32, i32* @TCSANOW
%75 = call i32 @tcsetattr(i32 %7, i32 %74, %struct.termios* %2)
br label %76
76: ; preds = %12, %9
%77 = phi i32 [ 0, %9 ], [ %7, %12 ]
ret i32 %77
}