#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 useconds_t;
typedef int uint8_t;
typedef scalar_t__ uint32_t;
typedef int adc_channel;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(scalar_t__);
scalar_t__ ioctl(scalar_t__, int /*<<< orphan*/, int);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(scalar_t__, int *, int);
int /*<<< orphan*/ scanf(char *, scalar_t__ *);
int /*<<< orphan*/ usleep(int);
scalar_t__ write(scalar_t__, int **, int);
int main(int argc, char **argv) {
  uint32_t fd;
  uint32_t ret;
  uint32_t adc_channel = 0;
  uint32_t dac_output = 0;
  uint8_t command[2] = {0};
  uint8_t value[4] = {0};
  useconds_t delay = 5000;
  char *dev = "/dev/i2c-0";
  printf("PCF8591 ADC and DAC test code\n");
  fd = open(dev, O_RDWR);
  if (fd < 0) {
    perror("Opening i2c device node\n");
    return -1;
  }
  ret = ioctl(fd, I2C_SLAVE, 0x48);
  if (ret < 0) {
    perror("Selecting i2c device\n");
    close(fd);
    return -1;
  }
  while (true) {
    printf("\n1. ADC 2. DAC 3. Exit\n");
    scanf("%d", &adc_channel);
    switch (adc_channel) {
    case 1:
      printf("\nEnter ADC channel number 0-3:\t");
      scanf("%d", &adc_channel);
      if ((adc_channel >= 0) && (adc_channel <= 3)) {
        command[0] = 0x40 | ((adc_channel)&0x03);
        command[1] = dac_output;
        ret = write(fd, &command, 2);
        if (ret != 2) {
          perror("i2c write failed");
          continue;
        }
        usleep(delay);
        ret = read(fd, &value[0], 1);
        if (ret != 1) {
          perror("i2c read failed");
          continue;
        }
        printf("\nADC Channel %d: value: %d\n", adc_channel, value[0]);
      } else {
        printf("Invalid ADC channel number\n");
      }
      break;
    case 2:
      printf("Enter DAC value:\t");
      scanf("%d", &dac_output);
      command[0] = 0x40 | ((adc_channel)&0x03);
      command[1] = dac_output & 0xff;
      ret = write(fd, &command, 2);
      if (ret != 2) {
        perror("i2c write failed");
        continue;
      }
      usleep(delay);
      break;
    case 3:
      goto exit;
      break;
    default:
      printf("Invalid input\n");
      break;
    }
  }
exit:
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
movl   $0x1388,-0x54(%rbp)
lea    0xe0c(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    123f <main+0x9f>
lea    0xdfc(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146a <main+0x2ca>
mov    -0x18(%rbp),%rdi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
mov    $0x48,%edx
call   1060 <ioctl@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1286 <main+0xe6>
lea    0xdd7(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    146a <main+0x2ca>
jmp    128b <main+0xeb>
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd1(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
sub    $0x1,%rax
je     12e6 <main+0x146>
jmp    12c0 <main+0x120>
mov    -0x68(%rbp),%rax
sub    $0x2,%rax
je     13c9 <main+0x229>
jmp    12d3 <main+0x133>
mov    -0x68(%rbp),%rax
sub    $0x3,%rax
je     1442 <main+0x2a2>
jmp    1447 <main+0x2a7>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd76(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <scanf@plt>
cmpq   $0x0,-0x28(%rbp)
jl     13b6 <main+0x216>
cmpq   $0x3,-0x28(%rbp)
jg     13b6 <main+0x216>
mov    -0x28(%rbp),%rax
and    $0x3,%rax
or     $0x40,%rax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
je     1362 <main+0x1c2>
lea    0xd3c(%rip),%rdi
call   10b0 <perror@plt>
jmp    128b <main+0xeb>
mov    -0x54(%rbp),%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
je     139c <main+0x1fc>
lea    0xd13(%rip),%rdi
call   10b0 <perror@plt>
jmp    128b <main+0xeb>
mov    -0x28(%rbp),%rsi
mov    -0x50(%rbp),%edx
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13c4 <main+0x224>
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1455 <main+0x2b5>
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc93(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x28(%rbp),%rax
and    $0x3,%rax
or     $0x40,%rax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
and    $0xff,%rax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
je     1435 <main+0x295>
lea    0xc69(%rip),%rdi
call   10b0 <perror@plt>
jmp    128b <main+0xeb>
mov    -0x54(%rbp),%edi
call   10c0 <usleep@plt>
jmp    1455 <main+0x2b5>
jmp    145a <main+0x2ba>
lea    0xcb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128b <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
call   10a0 <open@plt>
test   %rax,%rax
js     13b2 <main+0x212>
mov    %rax,%r15
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
mov    $0x48,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     13c5 <main+0x225>
lea    0xea6(%rip),%r14
lea    0xe0f(%rip),%rbx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%rbp
lea    0xec0(%rip),%r13
jmp    1250 <main+0xb0>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    0x10(%rsp),%rax
cmp    $0x1,%rax
je     1290 <main+0xf0>
cmp    $0x2,%rax
je     1320 <main+0x180>
cmp    $0x3,%rax
je     1399 <main+0x1f9>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1250 <main+0xb0>
nopl   0x0(%rax)
lea    0xda6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <scanf@plt>
mov    0x10(%rsp),%rax
cmp    $0x3,%rax
ja     123e <main+0x9e>
or     $0x40,%eax
mov    %eax,0x8(%rsp)
mov    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%rax
jne    1377 <main+0x1d7>
mov    $0x1388,%edi
call   10c0 <usleep@plt>
mov    %r15,%rdi
lea    0x20(%rsp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%rax
jne    1388 <main+0x1e8>
mov    0x10(%rsp),%rsi
mov    0x20(%rsp),%edx
lea    0xd6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xb0>
nop
lea    0xd73(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0x18(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x10(%rsp),%eax
and    $0x3,%eax
or     $0x40,%eax
mov    %eax,0x8(%rsp)
movzbl 0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%rax
jne    1377 <main+0x1d7>
mov    $0x1388,%edi
call   10c0 <usleep@plt>
jmp    1250 <main+0xb0>
lea    0xcdf(%rip),%rdi
call   10b0 <perror@plt>
jmp    1250 <main+0xb0>
lea    0xcdf(%rip),%rdi
call   10b0 <perror@plt>
jmp    1250 <main+0xb0>
mov    %r15,%rdi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc52(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    13a3 <main+0x203>
lea    0xc58(%rip),%rdi
call   10b0 <perror@plt>
mov    %r15,%rdi
call   1070 <close@plt>
mov    $0xffffffff,%eax
jmp    13a3 <main+0x203>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-0\00"
@.str.1 = [31 x i8] c"PCF8591 ADC and DAC test code\0A\00"
@O_RDWR = global i32 0
@.str.2 = [25 x i8] c"Opening i2c device node\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [22 x i8] c"Selecting i2c device\0A\00"
@.str.4 = [24 x i8] c"\0A1. ADC 2. DAC 3. Exit\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [32 x i8] c"\0AEnter ADC channel number 0-3:\09\00"
@.str.7 = [17 x i8] c"i2c write failed\00"
@.str.8 = [16 x i8] c"i2c read failed\00"
@.str.9 = [28 x i8] c"\0AADC Channel %d: value: %d\0A\00"
@.str.10 = [28 x i8] c"Invalid ADC channel number\0A\00"
@.str.11 = [18 x i8] c"Enter DAC value:\09\00"
@.str.12 = [15 x i8] c"Invalid input\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [2 x i32]
%11 = alloca [4 x i32]
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i64 0, i64* %9
%14 = bitcast [2 x i32]* %10 to i8*
%15 = bitcast [4 x i32]* %11 to i8*
store i32 5000, i32* %12
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %13
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %13
%18 = load i32, i32* @O_RDWR
%19 = call i64 @open(i8* %17, i32 %18)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %110
24: ; preds = %2
%25 = load i64, i64* %6
%26 = load i32, i32* @I2C_SLAVE
%27 = call i64 @ioctl(i64 %25, i32 %26, i32 72)
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%32 = load i64, i64* %6
%33 = call i32 @close(i64 %32)
store i32 -1, i32* %3
br label %110
34: ; preds = %24
br label %35
35: ; preds = %34, %61, %71, %98, %106
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %8)
%38 = load i64, i64* %8
switch i64 %38, label %104 [
i64 1, label %39
i64 2, label %81
i64 3, label %103
]
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %8)
%42 = load i64, i64* %8
%43 = icmp sge i64 %42, 0
br i1 %43, label %44, label %78
44: ; preds = %39
%45 = load i64, i64* %8
%46 = icmp sle i64 %45, 3
br i1 %46, label %47, label %78
47: ; preds = %44
%48 = load i64, i64* %8
%49 = and i64 %48, 3
%50 = or i64 64, %49
%51 = trunc i64 %50 to i32
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
store i32 %51, i32* %52
%53 = load i64, i64* %9
%54 = trunc i64 %53 to i32
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
store i32 %54, i32* %55
%56 = load i64, i64* %6
%57 = bitcast [2 x i32]* %10 to i32**
%58 = call i64 @write(i64 %56, i32** %57, i32 2)
store i64 %58, i64* %7
%59 = load i64, i64* %7
%60 = icmp ne i64 %59, 2
br i1 %60, label %61, label %63
61: ; preds = %47
%62 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %35
63: ; preds = %47
%64 = load i32, i32* %12
%65 = call i32 @usleep(i32 %64)
%66 = load i64, i64* %6
%67 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%68 = call i64 @read(i64 %66, i32* %67, i32 1)
store i64 %68, i64* %7
%69 = load i64, i64* %7
%70 = icmp ne i64 %69, 1
br i1 %70, label %71, label %73
71: ; preds = %63
%72 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %35
73: ; preds = %63
%74 = load i64, i64* %8
%75 = getelementptr inbounds [4 x i32], [4 x i32]* %11, i64 0, i64 0
%76 = load i32, i32* %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 %74, i32 %76)
br label %80
78: ; preds = %44, %39
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
br label %106
81: ; preds = %35
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%83 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %9)
%84 = load i64, i64* %8
%85 = and i64 %84, 3
%86 = or i64 64, %85
%87 = trunc i64 %86 to i32
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
store i32 %87, i32* %88
%89 = load i64, i64* %9
%90 = and i64 %89, 255
%91 = trunc i64 %90 to i32
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
store i32 %91, i32* %92
%93 = load i64, i64* %6
%94 = bitcast [2 x i32]* %10 to i32**
%95 = call i64 @write(i64 %93, i32** %94, i32 2)
store i64 %95, i64* %7
%96 = load i64, i64* %7
%97 = icmp ne i64 %96, 2
br i1 %97, label %98, label %100
98: ; preds = %81
%99 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %35
100: ; preds = %81
%101 = load i32, i32* %12
%102 = call i32 @usleep(i32 %101)
br label %106
103: ; preds = %35
br label %107
104: ; preds = %35
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %106
106: ; preds = %104, %100, %80
br label %35
107: ; preds = %103
%108 = load i64, i64* %6
%109 = call i32 @close(i64 %108)
store i32 0, i32* %3
br label %110
110: ; preds = %107, %30, %22
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-0\00"
@O_RDWR = global i32 0
@.str.2 = [25 x i8] c"Opening i2c device node\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [22 x i8] c"Selecting i2c device\0A\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [32 x i8] c"\0AEnter ADC channel number 0-3:\09\00"
@.str.7 = [17 x i8] c"i2c write failed\00"
@.str.8 = [16 x i8] c"i2c read failed\00"
@.str.9 = [28 x i8] c"\0AADC Channel %d: value: %d\0A\00"
@.str.11 = [18 x i8] c"Enter DAC value:\09\00"
@str = [30 x i8] c"PCF8591 ADC and DAC test code\00"
@str.13 = [23 x i8] c"\0A1. ADC 2. DAC 3. Exit\00"
@str.14 = [27 x i8] c"Invalid ADC channel number\00"
@str.15 = [14 x i8] c"Invalid input\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %5 to [2 x i32]*
%7 = alloca [4 x i32]
%8 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%9 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%10 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%11 = bitcast [4 x i32]* %7 to i8*
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @O_RDWR
%14 = tail call i64 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %81
18: ; preds = %2
%19 = load i32, i32* @I2C_SLAVE
%20 = tail call i64 @ioctl(i64 %14, i32 %19, i32 72)
%21 = icmp slt i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = bitcast i64* %5 to i32*
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%25 = bitcast i64* %5 to i32**
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
br label %30
27: ; preds = %18
%28 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @close(i64 %14)
br label %81
30: ; preds = %76, %22
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.13, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %3)
%33 = load i64, i64* %3
switch i64 %33, label %77 [
i64 1, label %34
i64 2, label %60
i64 3, label %79
]
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %3)
%37 = load i64, i64* %3
%38 = icmp ult i64 %37, 4
br i1 %38, label %39, label %58
39: ; preds = %34
%40 = trunc i64 %37 to i32
%41 = or i32 %40, 64
store i32 %41, i32* %23
%42 = load i64, i64* %4
%43 = trunc i64 %42 to i32
store i32 %43, i32* %24
%44 = call i64 @write(i64 %14, i32** %25, i32 2)
%45 = icmp eq i64 %44, 2
br i1 %45, label %48, label %46
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %76
48: ; preds = %39
%49 = call i32 @usleep(i32 5000)
%50 = call i64 @read(i64 %14, i32* %26, i32 1)
%51 = icmp eq i64 %50, 1
br i1 %51, label %54, label %52
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %76
54: ; preds = %48
%55 = load i64, i64* %3
%56 = load i32, i32* %26
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i64 %55, i32 %56)
br label %76
58: ; preds = %34
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0))
br label %76
60: ; preds = %30
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64* %4)
%63 = load i64, i64* %3
%64 = trunc i64 %63 to i32
%65 = and i32 %64, 3
%66 = or i32 %65, 64
store i32 %66, i32* %23
%67 = load i64, i64* %4
%68 = trunc i64 %67 to i32
%69 = and i32 %68, 255
store i32 %69, i32* %24
%70 = call i64 @write(i64 %14, i32** %25, i32 2)
%71 = icmp eq i64 %70, 2
br i1 %71, label %74, label %72
72: ; preds = %60
%73 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %76
74: ; preds = %60
%75 = call i32 @usleep(i32 5000)
br label %76
76: ; preds = %74, %77, %58, %54, %46, %52, %72
br label %30
77: ; preds = %30
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.15, i64 0, i64 0))
br label %76
79: ; preds = %30
%80 = call i32 @close(i64 %14)
br label %81
81: ; preds = %79, %27, %16
%82 = phi i32 [ -1, %16 ], [ -1, %27 ], [ 0, %79 ]
ret i32 %82
}