#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*/ O_RDWR;
int close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int write(int, int /*<<< orphan*/ *, size_t);
int main() {
  int currentdev = 0;
  char devname[256] = "/dev/mydevname0";
  int ret, fd0 = 0, fd1 = 0, fd2 = 0, *fd;
  int choice = 0;
  size_t len = 1;
  char str[256];
  while (choice != 6) {
    printf(
        "\nPlease choose operation:\n\t1: read\n\t2: write\n\t3: open\n\t4: "
        "close\n\t5: next device\n\t6: exit this program\nYour choice(1~6): ");
    scanf("%[^\n]%*c", str);
    sscanf(str, "%d", &choice);
    printf("choice: %s -> %d\n", str, choice);
    switch (currentdev) {
    case 0:
      fd = &fd0;
      break;
    case 1:
      fd = &fd1;
      break;
    case 2:
      fd = &fd2;
      break;
    }
    switch (choice) {
    case 1:
      if (*fd <= 0) {
        printf("mydevname%d not open. Please first open the device\n",
               currentdev);
        break;
      }
      ret = read(*fd, NULL, len);
      if (ret < 0) {
        perror("Fail to read.\n");
        return errno;
      }
      break;
    case 2:
      if (*fd <= 0) {
        printf("mydevname%d not open. Please first open the device\n",
               currentdev);
        break;
      }
      ret = write(*fd, NULL, len);
      if (ret < 0) {
        perror("Fail to write.\n");
        return errno;
      }
      break;
    case 3:
      if (*fd > 0) {
        printf("mydevname%d already open.\n", currentdev);
        break;
      }
      *fd = open(devname, O_RDWR);
      if (*fd < 0) {
        perror("Fail to open the device...");
        return errno;
      }
      break;
    case 4:
      if (*fd == 0) {
        printf("Device already closed.\n");
        break;
      }
      ret = close(*fd);
      if (ret < 0) {
        perror("Device fail to close.\n");
        return errno;
      }
      *fd = 0;
      break;
    case 5:
      currentdev = (currentdev + 1) % 3;
      sprintf(devname, "/dev/mydevname%d", currentdev);
      printf("Current device is %s\n", devname);
      break;
    case 6:
      return 0;
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe59(%rip),%rsi
mov    $0x100,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
movl   $0x0,-0x12c(%rbp)
movq   $0x1,-0x138(%rbp)
cmpl   $0x6,-0x12c(%rbp)
je     1546 <main+0x3a6>
lea    0xf08(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x245(%rbp)
call   1040 <printf@plt>
lea    0xf6d(%rip),%rdi
lea    -0x240(%rbp),%rsi
mov    %rsi,-0x250(%rbp)
call   1090 <scanf@plt>
mov    -0x250(%rbp),%rdi
lea    0x102d(%rip),%rsi
lea    -0x12c(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x250(%rbp),%rsi
mov    -0x245(%rbp),%al
mov    -0x12c(%rbp),%edx
lea    0xf2f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x244(%rbp)
test   %eax,%eax
je     12b6 <main+0x116>
jmp    128e <main+0xee>
mov    -0x244(%rbp),%eax
sub    $0x1,%eax
je     12c9 <main+0x129>
jmp    12a2 <main+0x102>
mov    -0x244(%rbp),%eax
sub    $0x2,%eax
je     12dc <main+0x13c>
jmp    12ea <main+0x14a>
lea    -0x118(%rbp),%rax
mov    %rax,-0x128(%rbp)
jmp    12ea <main+0x14a>
lea    -0x11c(%rbp),%rax
mov    %rax,-0x128(%rbp)
jmp    12ea <main+0x14a>
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x258(%rbp)
sub    $0x5,%eax
ja     153c <main+0x39c>
mov    -0x258(%rbp),%rax
lea    0xced(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x128(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1342 <main+0x1a2>
mov    -0x8(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
mov    (%rax),%edi
mov    -0x138(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    138b <main+0x1eb>
lea    0xe73(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    154d <main+0x3ad>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
cmpl   $0x0,(%rax)
jg     13b6 <main+0x216>
mov    -0x8(%rbp),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
mov    (%rax),%edi
mov    -0x138(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <write@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    13ff <main+0x25f>
lea    0xe0e(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    154d <main+0x3ad>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
cmpl   $0x0,(%rax)
jle    142a <main+0x28a>
mov    -0x8(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1541 <main+0x3a1>
lea    -0x110(%rbp),%rdi
mov    0x2bb0(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x128(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1477 <main+0x2d7>
lea    0xdc1(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2b6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    154d <main+0x3ad>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
cmpl   $0x0,(%rax)
jne    149f <main+0x2ff>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1541 <main+0x3a1>
mov    -0x128(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    14dd <main+0x33d>
lea    0xd8e(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2b05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    154d <main+0x3ad>
mov    -0x128(%rbp),%rax
movl   $0x0,(%rax)
jmp    1541 <main+0x3a1>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xd5b(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1541 <main+0x3a1>
movl   $0x0,-0x4(%rbp)
jmp    154d <main+0x3ad>
jmp    1541 <main+0x3a1>
jmp    1204 <main+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
lea    0xe58(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x100,%edx
call   1080 <memcpy@plt>
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x120(%rsp),%rbx
lea    0x105c(%rip),%r14
lea    0xc(%rsp),%rbp
xor    %r15d,%r15d
jmp    1277 <main+0xc7>
add    $0x1,%r15d
movslq %r15d,%r15
imul   $0x55555556,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%r15d
mov    %rbx,%rbp
mov    %r14,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
lea    0x100e(%rip),%rsi
mov    %r15d,%edx
call   10d0 <sprintf@plt>
lea    0x1010(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%r14
mov    %rbp,%rbx
lea    0xc(%rsp),%rbp
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x6,%eax
je     13fc <main+0x24c>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf0d(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1090 <sscanf@plt>
mov    0xc(%rsp),%edx
lea    0xef5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r15d
je     12d0 <main+0x120>
cmp    $0x1,%r15d
je     12e0 <main+0x130>
test   %r15d,%r15d
jne    12e5 <main+0x135>
lea    0x1c(%rsp),%r13
jmp    12e5 <main+0x135>
nop
lea    0x14(%rsp),%r13
jmp    12e5 <main+0x135>
nopw   0x0(%rax,%rax,1)
lea    0x18(%rsp),%r13
movl   $0x0,0x10(%rsp)
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x5,%ecx
ja     126e <main+0xbe>
lea    0xcfc(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    0x0(%r13),%edi
test   %edi,%edi
jle    137d <main+0x1cd>
mov    $0x1,%edx
xor    %esi,%esi
call   1070 <read@plt>
test   %eax,%eax
jns    126a <main+0xba>
jmp    13c8 <main+0x218>
mov    0x0(%r13),%edi
test   %edi,%edi
jle    137d <main+0x1cd>
mov    $0x1,%edx
xor    %esi,%esi
call   1040 <write@plt>
test   %eax,%eax
jns    126a <main+0xba>
jmp    13d1 <main+0x221>
cmpl   $0x0,0x0(%r13)
jle    1393 <main+0x1e3>
lea    0xeaa(%rip),%rdi
jmp    1384 <main+0x1d4>
mov    0x0(%r13),%edi
test   %edi,%edi
je     13b7 <main+0x207>
call   1060 <close@plt>
test   %eax,%eax
js     13da <main+0x22a>
movl   $0x0,0x0(%r13)
jmp    126a <main+0xba>
lea    0xe30(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    126a <main+0xba>
mov    %r13,%r12
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdi
call   10b0 <open@plt>
mov    %eax,0x0(%r13)
test   %eax,%eax
jns    126a <main+0xba>
jmp    13e3 <main+0x233>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
jmp    126a <main+0xba>
lea    0xe19(%rip),%rdi
jmp    13ea <main+0x23a>
lea    0xe1f(%rip),%rdi
jmp    13ea <main+0x23a>
lea    0xe5c(%rip),%rdi
jmp    13ea <main+0x23a>
lea    0xe38(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2be2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x10(%rsp),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.devname = [256 x i8] c"/dev/mydevname0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [121 x i8] c"\0APlease choose operation:\0A\091: read\0A\092: write\0A\093: open\0A\094: close\0A\095: next device\0A\096: exit this program\0AYour choice(1~6): \00"
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"choice: %s -> %d\0A\00"
@.str.4 = [52 x i8] c"mydevname%d not open. Please first open the device\0A\00"
@.str.5 = [15 x i8] c"Fail to read.\0A\00"
@errno = global i32 0
@.str.6 = [16 x i8] c"Fail to write.\0A\00"
@.str.7 = [27 x i8] c"mydevname%d already open.\0A\00"
@O_RDWR = global i32 0
@.str.8 = [27 x i8] c"Fail to open the device...\00"
@.str.9 = [24 x i8] c"Device already closed.\0A\00"
@.str.10 = [23 x i8] c"Device fail to close.\0A\00"
@.str.11 = [17 x i8] c"/dev/mydevname%d\00"
@.str.12 = [22 x i8] c"Current device is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
%11 = alloca [256 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%12 = bitcast [256 x i8]* %3 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %9
store i64 1, i64* %10
br label %13
13: ; preds = %114, %0
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 6
br i1 %15, label %16, label %115
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%19 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%23 = load i32, i32* %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %22, i32 %23)
%25 = load i32, i32* %2
switch i32 %25, label %29 [
i32 0, label %26
i32 1, label %27
i32 2, label %28
]
26: ; preds = %16
store i32* %5, i32** %8
br label %29
27: ; preds = %16
store i32* %6, i32** %8
br label %29
28: ; preds = %16
store i32* %7, i32** %8
br label %29
29: ; preds = %16, %28, %27, %26
%30 = load i32, i32* %9
switch i32 %30, label %113 [
i32 1, label %31
i32 2, label %49
i32 3, label %67
i32 4, label %86
i32 5, label %103
i32 6, label %112
]
31: ; preds = %29
%32 = load i32*, i32** %8
%33 = load i32, i32* %32
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %114
38: ; preds = %31
%39 = load i32*, i32** %8
%40 = load i32, i32* %39
%41 = load i64, i64* %10
%42 = call i32 @read(i32 %40, i32* null, i64 %41)
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @errno
store i32 %47, i32* %1
br label %116
48: ; preds = %38
br label %114
49: ; preds = %29
%50 = load i32*, i32** %8
%51 = load i32, i32* %50
%52 = icmp sle i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %114
56: ; preds = %49
%57 = load i32*, i32** %8
%58 = load i32, i32* %57
%59 = load i64, i64* %10
%60 = call i32 @write(i32 %58, i32* null, i64 %59)
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %56
%64 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32, i32* @errno
store i32 %65, i32* %1
br label %116
66: ; preds = %56
br label %114
67: ; preds = %29
%68 = load i32*, i32** %8
%69 = load i32, i32* %68
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32, i32* %2
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %72)
br label %114
74: ; preds = %67
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%76 = load i32, i32* @O_RDWR
%77 = call i32 @open(i8* %75, i32 %76)
%78 = load i32*, i32** %8
store i32 %77, i32* %78
%79 = load i32*, i32** %8
%80 = load i32, i32* %79
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %74
%83 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%84 = load i32, i32* @errno
store i32 %84, i32* %1
br label %116
85: ; preds = %74
br label %114
86: ; preds = %29
%87 = load i32*, i32** %8
%88 = load i32, i32* %87
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %114
92: ; preds = %86
%93 = load i32*, i32** %8
%94 = load i32, i32* %93
%95 = call i32 @close(i32 %94)
store i32 %95, i32* %4
%96 = load i32, i32* %4
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %92
%99 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%100 = load i32, i32* @errno
store i32 %100, i32* %1
br label %116
101: ; preds = %92
%102 = load i32*, i32** %8
store i32 0, i32* %102
br label %114
103: ; preds = %29
%104 = load i32, i32* %2
%105 = add nsw i32 %104, 1
%106 = srem i32 %105, 3
store i32 %106, i32* %2
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%108 = load i32, i32* %2
%109 = call i32 @sprintf(i8* %107, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %108)
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %110)
br label %114
112: ; preds = %29
store i32 0, i32* %1
br label %116
113: ; preds = %29
br label %114
114: ; preds = %113, %103, %101, %90, %85, %71, %66, %53, %48, %35
br label %13
115: ; preds = %13
store i32 0, i32* %1
br label %116
116: ; preds = %115, %112, %98, %82, %63, %45
%117 = load i32, i32* %1
ret i32 %117
}

LLVM IR (-O2):
@__const.main.devname = [256 x i8] c"/dev/mydevname0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [121 x i8] c"\0APlease choose operation:\0A\091: read\0A\092: write\0A\093: open\0A\094: close\0A\095: next device\0A\096: exit this program\0AYour choice(1~6): \00"
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"choice: %s -> %d\0A\00"
@.str.4 = [52 x i8] c"mydevname%d not open. Please first open the device\0A\00"
@.str.5 = [15 x i8] c"Fail to read.\0A\00"
@errno = global i32 0
@.str.6 = [16 x i8] c"Fail to write.\0A\00"
@.str.7 = [27 x i8] c"mydevname%d already open.\0A\00"
@O_RDWR = global i32 0
@.str.8 = [27 x i8] c"Fail to open the device...\00"
@.str.10 = [23 x i8] c"Device fail to close.\0A\00"
@.str.11 = [17 x i8] c"/dev/mydevname%d\00"
@.str.12 = [22 x i8] c"Current device is %s\0A\00"
@str = [23 x i8] c"Device already closed.\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%8 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %13
13: ; preds = %0, %69
%14 = phi i32* [ undef, %0 ], [ %25, %69 ]
%15 = phi i32 [ 0, %0 ], [ %71, %69 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%18 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 %19)
switch i32 %15, label %24 [
i32 0, label %21
i32 1, label %22
i32 2, label %23
]
21: ; preds = %13
br label %24
22: ; preds = %13
br label %24
23: ; preds = %13
br label %24
24: ; preds = %13, %23, %22, %21
%25 = phi i32* [ %14, %13 ], [ %4, %23 ], [ %3, %22 ], [ %2, %21 ]
%26 = load i32, i32* %5
switch i32 %26, label %69 [
i32 1, label %27
i32 2, label %35
i32 3, label %43
i32 4, label %52
i32 5, label %61
i32 6, label %77
]
27: ; preds = %24
%28 = load i32, i32* %25
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %66
32: ; preds = %27
%33 = call i32 @read(i32 %28, i32* null, i64 1)
%34 = icmp slt i32 %33, 0
br i1 %34, label %73, label %66
35: ; preds = %24
%36 = load i32, i32* %25
%37 = icmp slt i32 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %66
40: ; preds = %35
%41 = call i32 @write(i32 %36, i32* null, i64 1)
%42 = icmp slt i32 %41, 0
br i1 %42, label %73, label %66
43: ; preds = %24
%44 = load i32, i32* %25
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %15)
br label %66
48: ; preds = %43
%49 = load i32, i32* @O_RDWR
%50 = call i32 @open(i8* %7, i32 %49)
store i32 %50, i32* %25
%51 = icmp slt i32 %50, 0
br i1 %51, label %73, label %66
52: ; preds = %24
%53 = load i32, i32* %25
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %66
57: ; preds = %52
%58 = call i32 @close(i32 %53)
%59 = icmp slt i32 %58, 0
br i1 %59, label %73, label %60
60: ; preds = %57
store i32 0, i32* %25
br label %66
61: ; preds = %24
%62 = add nsw i32 %15, 1
%63 = srem i32 %62, 3
%64 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %7)
br label %66
66: ; preds = %30, %38, %46, %55, %60, %61, %32, %40, %48
%67 = phi i32 [ %15, %32 ], [ %15, %30 ], [ %15, %40 ], [ %15, %38 ], [ %15, %48 ], [ %15, %46 ], [ %15, %60 ], [ %15, %55 ], [ %63, %61 ]
%68 = load i32, i32* %5
br label %69
69: ; preds = %66, %24
%70 = phi i32 [ %68, %66 ], [ %26, %24 ]
%71 = phi i32 [ %67, %66 ], [ %15, %24 ]
%72 = icmp eq i32 %70, 6
br i1 %72, label %77, label %13
73: ; preds = %57, %48, %40, %32
%74 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %32 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), %40 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), %48 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), %57 ]
%75 = call i32 @perror(i8* %74)
%76 = load i32, i32* @errno
br label %77
77: ; preds = %69, %24, %73
%78 = phi i32 [ %76, %73 ], [ 0, %24 ], [ 0, %69 ]
ret i32 %78
}