#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ logger(int /*<<< orphan*/);
int /*<<< orphan*/ msg_err(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write_2_led(char, char);
void set_state(unsigned s) {
  int ret;
  switch (s) {
  case 0:
    ret = write_2_led('0', '1');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('1', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('2', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    break;
  case 1:
    ret = write_2_led('0', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('1', '1');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('2', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    break;
  case 2:
    ret = write_2_led('0', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('1', '0');
    if (ret == -1)
      logger(msg_err("Error", errno));
    ret = write_2_led('2', '1');
    if (ret == -1)
      logger(msg_err("Error", errno));
    break;
  default:
    fprintf(stderr, "Wrong state\n");
    break;
  }
}


x86 assembly (clang, -O0):
<set_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
test   %eax,%eax
je     1180 <set_state+0x40>
jmp    115e <set_state+0x1e>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
je     122d <set_state+0xed>
jmp    116f <set_state+0x2f>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
je     12d4 <set_state+0x194>
jmp    137e <set_state+0x23e>
mov    $0x30,%edi
mov    $0x31,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b8 <set_state+0x78>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11f0 <set_state+0xb0>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x32,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1228 <set_state+0xe8>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xde4(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
jmp    1393 <set_state+0x253>
mov    $0x30,%esi
mov    %esi,%edi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1262 <set_state+0x122>
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
lea    0xdaa(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%esi
mov    %esi,%edi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1297 <set_state+0x157>
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
lea    0xd75(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x32,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12cf <set_state+0x18f>
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
lea    0xd3d(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
jmp    1393 <set_state+0x253>
mov    $0x30,%esi
mov    %esi,%edi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1309 <set_state+0x1c9>
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
lea    0xd03(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1341 <set_state+0x201>
mov    0x2cac(%rip),%rax
mov    (%rax),%esi
lea    0xccb(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x32,%edi
mov    $0x31,%esi
call   1060 <write_2_led@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1379 <set_state+0x239>
mov    0x2c74(%rip),%rax
mov    (%rax),%esi
lea    0xc93(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
jmp    1393 <set_state+0x253>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xc78(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_state>:
push   %rax
cmp    $0x2,%edi
je     1196 <set_state+0x56>
cmp    $0x1,%edi
je     1202 <set_state+0xc2>
test   %edi,%edi
jne    1295 <set_state+0x155>
mov    $0x30,%edi
mov    $0x31,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
jne    1187 <set_state+0x47>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%edi
mov    $0x30,%esi
jmp    123c <set_state+0xfc>
mov    $0x30,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
jne    11c6 <set_state+0x86>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
jne    11f6 <set_state+0xb6>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    0xe16(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x32,%edi
mov    $0x31,%esi
jmp    126c <set_state+0x12c>
mov    $0x30,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
jne    1232 <set_state+0xf2>
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
lea    0xdda(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x31,%edi
mov    $0x31,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
jne    1262 <set_state+0x122>
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
lea    0xdaa(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
call   1040 <logger@plt>
mov    $0x32,%edi
mov    $0x30,%esi
call   1060 <write_2_led@plt>
cmp    $0xffffffff,%eax
je     1278 <set_state+0x138>
pop    %rax
ret
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
lea    0xd78(%rip),%rdi
call   1050 <msg_err@plt>
mov    %eax,%edi
pop    %rax
jmp    1040 <logger@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
pop    %rax
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"Error\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [13 x i8] c"Wrong state\0A\00"
define void @set_state(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %80 [
i32 0, label %5
i32 1, label %30
i32 2, label %55
]
5: ; preds = %1
%6 = call i32 @write_2_led(i8 signext 48, i8 signext 49)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i32, i32* @errno
%11 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @logger(i32 %11)
br label %13
13: ; preds = %9, %5
%14 = call i32 @write_2_led(i8 signext 49, i8 signext 48)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @logger(i32 %19)
br label %21
21: ; preds = %17, %13
%22 = call i32 @write_2_led(i8 signext 50, i8 signext 48)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @errno
%27 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = call i32 @logger(i32 %27)
br label %29
29: ; preds = %25, %21
br label %83
30: ; preds = %1
%31 = call i32 @write_2_led(i8 signext 48, i8 signext 48)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @errno
%36 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = call i32 @logger(i32 %36)
br label %38
38: ; preds = %34, %30
%39 = call i32 @write_2_led(i8 signext 49, i8 signext 49)
store i32 %39, i32* %3
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @errno
%44 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = call i32 @logger(i32 %44)
br label %46
46: ; preds = %42, %38
%47 = call i32 @write_2_led(i8 signext 50, i8 signext 48)
store i32 %47, i32* %3
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i32, i32* @errno
%52 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = call i32 @logger(i32 %52)
br label %54
54: ; preds = %50, %46
br label %83
55: ; preds = %1
%56 = call i32 @write_2_led(i8 signext 48, i8 signext 48)
store i32 %56, i32* %3
%57 = load i32, i32* %3
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* @errno
%61 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = call i32 @logger(i32 %61)
br label %63
63: ; preds = %59, %55
%64 = call i32 @write_2_led(i8 signext 49, i8 signext 48)
store i32 %64, i32* %3
%65 = load i32, i32* %3
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %63
%68 = load i32, i32* @errno
%69 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %68)
%70 = call i32 @logger(i32 %69)
br label %71
71: ; preds = %67, %63
%72 = call i32 @write_2_led(i8 signext 50, i8 signext 49)
store i32 %72, i32* %3
%73 = load i32, i32* %3
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %71
%76 = load i32, i32* @errno
%77 = call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %76)
%78 = call i32 @logger(i32 %77)
br label %79
79: ; preds = %75, %71
br label %83
80: ; preds = %1
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %83
83: ; preds = %80, %79, %54, %29
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [13 x i8] c"Wrong state\0A\00"
define void @set_state(i32 %0) {
switch i32 %0, label %65 [
i32 0, label %2
i32 1, label %23
i32 2, label %44
]
2: ; preds = %1
%3 = tail call i32 @write_2_led(i8 signext 48, i8 signext 49)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @errno
%7 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @logger(i32 %7)
br label %9
9: ; preds = %5, %2
%10 = tail call i32 @write_2_led(i8 signext 49, i8 signext 48)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 @logger(i32 %14)
br label %16
16: ; preds = %12, %9
%17 = tail call i32 @write_2_led(i8 signext 50, i8 signext 48)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %68
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = tail call i32 @logger(i32 %21)
br label %68
23: ; preds = %1
%24 = tail call i32 @write_2_led(i8 signext 48, i8 signext 48)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = tail call i32 @logger(i32 %28)
br label %30
30: ; preds = %26, %23
%31 = tail call i32 @write_2_led(i8 signext 49, i8 signext 49)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @errno
%35 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = tail call i32 @logger(i32 %35)
br label %37
37: ; preds = %33, %30
%38 = tail call i32 @write_2_led(i8 signext 50, i8 signext 48)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %68
40: ; preds = %37
%41 = load i32, i32* @errno
%42 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = tail call i32 @logger(i32 %42)
br label %68
44: ; preds = %1
%45 = tail call i32 @write_2_led(i8 signext 48, i8 signext 48)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @errno
%49 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = tail call i32 @logger(i32 %49)
br label %51
51: ; preds = %47, %44
%52 = tail call i32 @write_2_led(i8 signext 49, i8 signext 48)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32, i32* @errno
%56 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = tail call i32 @logger(i32 %56)
br label %58
58: ; preds = %54, %51
%59 = tail call i32 @write_2_led(i8 signext 50, i8 signext 49)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %68
61: ; preds = %58
%62 = load i32, i32* @errno
%63 = tail call i32 @msg_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = tail call i32 @logger(i32 %63)
br label %68
65: ; preds = %1
%66 = load i32, i32* @stderr
%67 = tail call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %58, %61, %37, %40, %16, %19, %65
ret void
}