#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*/ buildpacket(unsigned char *, int *, int, unsigned char *,
                               int);
int listen(int, unsigned char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
void toggleshutter(int fd, int *shutter) {
  unsigned char pak[1024];
  unsigned char buf[1024];
  int len, res;
  unsigned char p[2];
  p[1] = 0x00;
  if (*shutter == 1) {
    p[0] = 0x01;
    *shutter = 0;
    printf("Closing shutter.\n");
  } else if (*shutter == 0) {
    p[0] = 0X00;
    *shutter = 1;
    printf("Opening shutter.\n");
  }
  buildpacket(pak, &len, 0x04, p, 2);
  write(fd, pak, len);
  res = listen(fd, buf);
  if (!(res == 1 && buf[0] == 0x06))
    printf("ACK not received.  Check connection.\n");
}


x86 assembly (clang, -O0):
<toggleshutter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x819(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1188 <toggleshutter+0x48>
movb   $0x1,-0x81a(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <toggleshutter+0x77>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11b2 <toggleshutter+0x72>
movb   $0x0,-0x81a(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <toggleshutter+0x77>
lea    -0x410(%rbp),%rdi
lea    -0x81a(%rbp),%rcx
lea    -0x814(%rbp),%rsi
mov    $0x4,%edx
mov    $0x2,%r8d
call   1050 <buildpacket@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1060 <listen@plt>
mov    %eax,-0x818(%rbp)
cmpl   $0x1,-0x818(%rbp)
jne    1223 <toggleshutter+0xe3>
movzbl -0x810(%rbp),%eax
cmp    $0x6,%eax
je     122f <toggleshutter+0xef>
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toggleshutter>:
push   %rbp
push   %rbx
sub    $0x818,%rsp
mov    %edi,%ebp
movb   $0x0,0xb(%rsp)
mov    (%rsi),%eax
cmp    $0x1,%eax
je     116b <toggleshutter+0x2b>
test   %eax,%eax
jne    1181 <toggleshutter+0x41>
lea    0xec3(%rip),%rdi
mov    $0x1,%eax
xor    %ecx,%ecx
jmp    1176 <toggleshutter+0x36>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
mov    $0x1,%cl
mov    %cl,0xa(%rsp)
mov    %eax,(%rsi)
call   1030 <puts@plt>
lea    0x410(%rsp),%rbx
lea    0xc(%rsp),%rsi
lea    0xa(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x4,%edx
mov    $0x2,%r8d
call   1050 <buildpacket@plt>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
call   1060 <listen@plt>
cmp    $0x1,%eax
jne    11cc <toggleshutter+0x8c>
cmpb   $0x6,0x10(%rsp)
je     11d8 <toggleshutter+0x98>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
add    $0x818,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Closing shutter.\0A\00"
@.str.1 = [18 x i8] c"Opening shutter.\0A\00"
@.str.2 = [38 x i8] c"ACK not received. Check connection.\0A\00"
define void @toggleshutter(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
store i8 0, i8* %10
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 1, i8* %15
%16 = load i32*, i32** %4
store i32 0, i32* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %27
18: ; preds = %2
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
store i8 0, i8* %23
%24 = load i32*, i32** %4
store i32 1, i32* %24
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %22, %18
br label %27
27: ; preds = %26, %14
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%30 = call i32 @buildpacket(i8* %28, i32* %7, i32 4, i8* %29, i32 2)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* %7
%34 = call i32 @write(i32 %31, i8* %32, i32 %33)
%35 = load i32, i32* %3
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = call i32 @listen(i32 %35, i8* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %45
40: ; preds = %27
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 6
br i1 %44, label %47, label %45
45: ; preds = %40, %27
%46 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
ret void
}

LLVM IR (-O2):
@str = [37 x i8] c"ACK not received. Check connection.\00"
@str.3 = [17 x i8] c"Opening shutter.\00"
@str.4 = [17 x i8] c"Closing shutter.\00"
define void @toggleshutter(i32 %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca [2 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 0, i8* %11
%12 = load i32, i32* %1
switch i32 %12, label %19 [
i32 1, label %14
i32 0, label %13
]
13: ; preds = %2
br label %14
14: ; preds = %2, %13
%15 = phi i8 [ 0, %13 ], [ 1, %2 ]
%16 = phi i32 [ 1, %13 ], [ 0, %2 ]
%17 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0), %2 ]
store i8 %15, i8* %10
store i32 %16, i32* %1
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
br label %19
19: ; preds = %14, %2
%20 = call i32 @buildpacket(i8* %7, i32* %5, i32 4, i8* %10, i32 2)
%21 = load i32, i32* %5
%22 = call i32 @write(i32 %0, i8* %7, i32 %21)
%23 = call i32 @listen(i32 %0, i8* %8)
%24 = icmp eq i32 %23, 1
%25 = load i8, i8* %8
%26 = icmp eq i8 %25, 6
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %30, label %28
28: ; preds = %19
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %19, %28
ret void
}