#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 AFMT_S16_BE;
int AFMT_S16_LE;
int AFMT_S8;
int AFMT_U16_BE;
int AFMT_U16_LE;
int AFMT_U8;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SNDCTL_DSP_CHANNELS;
int /*<<< orphan*/ SNDCTL_DSP_SETFMT;
int /*<<< orphan*/ SNDCTL_DSP_SPEED;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setupdsp(unsigned char size, unsigned char sign, unsigned char bigendian,
             unsigned int speed, unsigned int channels) {
  int dsp, format;
  if (sign) {
    if (size == 8)
      format = AFMT_S8;
    else if (bigendian)
      format = AFMT_S16_BE;
    else
      format = AFMT_S16_LE;
  } else {
    if (size == 8)
      format = AFMT_U8;
    else if (bigendian)
      format = AFMT_U16_BE;
    else
      format = AFMT_U16_LE;
  }
  if ((dsp = open("/dev/sound/dsp", O_WRONLY)) == -1) {
    perror("could not open dsp-device");
    return -1;
  }
  if (ioctl(dsp, SNDCTL_DSP_SETFMT, &format) == -1) {
    perror("could not set format");
    close(dsp);
    return -1;
  }
  if (ioctl(dsp, SNDCTL_DSP_CHANNELS, &channels) == -1) {
    perror("could not set channels");
    close(dsp);
    return -1;
  }
  if (ioctl(dsp, SNDCTL_DSP_SPEED, &speed) == -1) {
    perror("could not set speed");
    close(dsp);
    return -1;
  }
  return dsp;
}


x86 assembly (clang, -O0):
<setupdsp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x5(%rbp)
mov    %dl,-0x6(%rbp)
mov    %al,-0x7(%rbp)
mov    %ecx,-0xc(%rbp)
mov    %r8d,-0x10(%rbp)
cmpb   $0x0,-0x6(%rbp)
je     11ba <setupdsp+0x7a>
movzbl -0x5(%rbp),%eax
cmp    $0x8,%eax
jne    1189 <setupdsp+0x49>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <setupdsp+0x75>
cmpb   $0x0,-0x7(%rbp)
je     11a4 <setupdsp+0x64>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <setupdsp+0x70>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11b5 <setupdsp+0x75>
jmp    1209 <setupdsp+0xc9>
movzbl -0x5(%rbp),%eax
cmp    $0x8,%eax
jne    11d8 <setupdsp+0x98>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1204 <setupdsp+0xc4>
cmpb   $0x0,-0x7(%rbp)
je     11f3 <setupdsp+0xb3>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11ff <setupdsp+0xbf>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1204 <setupdsp+0xc4>
jmp    1209 <setupdsp+0xc9>
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    0xde7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1242 <setupdsp+0x102>
lea    0xdde(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1308 <setupdsp+0x1c8>
mov    -0x14(%rbp),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1282 <setupdsp+0x142>
lea    0xdc0(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1308 <setupdsp+0x1c8>
mov    -0x14(%rbp),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12c2 <setupdsp+0x182>
lea    0xd95(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1308 <setupdsp+0x1c8>
mov    -0x14(%rbp),%edi
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1302 <setupdsp+0x1c2>
lea    0xd6c(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1308 <setupdsp+0x1c8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupdsp>:
push   %rbx
sub    $0x10,%rsp
mov    %ecx,0xc(%rsp)
mov    %r8d,0x8(%rsp)
test   %esi,%esi
je     1161 <setupdsp+0x21>
cmp    $0x8,%dil
jne    1170 <setupdsp+0x30>
mov    0x2e61(%rip),%rax
jmp    119a <setupdsp+0x5a>
cmp    $0x8,%dil
jne    117d <setupdsp+0x3d>
mov    0x2e22(%rip),%rax
jmp    119a <setupdsp+0x5a>
test   %dl,%dl
je     118a <setupdsp+0x4a>
mov    0x2e55(%rip),%rax
jmp    119a <setupdsp+0x5a>
test   %dl,%dl
je     1193 <setupdsp+0x53>
mov    0x2e60(%rip),%rax
jmp    119a <setupdsp+0x5a>
mov    0x2e47(%rip),%rax
jmp    119a <setupdsp+0x5a>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1219 <setupdsp+0xd9>
mov    %eax,%ebx
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1227 <setupdsp+0xe7>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1230 <setupdsp+0xf0>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1248 <setupdsp+0x108>
lea    0xe3e(%rip),%rdi
jmp    1237 <setupdsp+0xf7>
lea    0xdef(%rip),%rdi
call   1060 <perror@plt>
jmp    1243 <setupdsp+0x103>
lea    0xdfb(%rip),%rdi
jmp    1237 <setupdsp+0xf7>
lea    0xe07(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@AFMT_S8 = global i32 0
@AFMT_S16_BE = global i32 0
@AFMT_S16_LE = global i32 0
@AFMT_U8 = global i32 0
@AFMT_U16_BE = global i32 0
@AFMT_U16_LE = global i32 0
@.str = [15 x i8] c"/dev/sound/dsp\00"
@O_WRONLY = global i32 0
@.str.1 = [26 x i8] c"could not open dsp-device\00"
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [21 x i8] c"could not set format\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.3 = [23 x i8] c"could not set channels\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [20 x i8] c"could not set speed\00"
define i32 @setupdsp(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8 %0, i8* %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load i8, i8* %8
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %5
%17 = load i8, i8* %7
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 8
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @AFMT_S8
store i32 %21, i32* %13
br label %30
22: ; preds = %16
%23 = load i8, i8* %9
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* @AFMT_S16_BE
store i32 %26, i32* %13
br label %29
27: ; preds = %22
%28 = load i32, i32* @AFMT_S16_LE
store i32 %28, i32* %13
br label %29
29: ; preds = %27, %25
br label %30
30: ; preds = %29, %20
br label %46
31: ; preds = %5
%32 = load i8, i8* %7
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %33, 8
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* @AFMT_U8
store i32 %36, i32* %13
br label %45
37: ; preds = %31
%38 = load i8, i8* %9
%39 = icmp ne i8 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = load i32, i32* @AFMT_U16_BE
store i32 %41, i32* %13
br label %44
42: ; preds = %37
%43 = load i32, i32* @AFMT_U16_LE
store i32 %43, i32* %13
br label %44
44: ; preds = %42, %40
br label %45
45: ; preds = %44, %35
br label %46
46: ; preds = %45, %30
%47 = load i32, i32* @O_WRONLY
%48 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %47)
store i32 %48, i32* %12
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %81
52: ; preds = %46
%53 = load i32, i32* %12
%54 = load i32, i32* @SNDCTL_DSP_SETFMT
%55 = call i32 (i32, i32, ...) @ioctl(i32 %53, i32 %54, i32* %13)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* %12
%60 = call i32 @close(i32 %59)
store i32 -1, i32* %6
br label %81
61: ; preds = %52
%62 = load i32, i32* %12
%63 = load i32, i32* @SNDCTL_DSP_CHANNELS
%64 = call i32 (i32, i32, ...) @ioctl(i32 %62, i32 %63, i32* %11)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%68 = load i32, i32* %12
%69 = call i32 @close(i32 %68)
store i32 -1, i32* %6
br label %81
70: ; preds = %61
%71 = load i32, i32* %12
%72 = load i32, i32* @SNDCTL_DSP_SPEED
%73 = call i32 (i32, i32, ...) @ioctl(i32 %71, i32 %72, i32* %10)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* %12
%78 = call i32 @close(i32 %77)
store i32 -1, i32* %6
br label %81
79: ; preds = %70
%80 = load i32, i32* %12
store i32 %80, i32* %6
br label %81
81: ; preds = %79, %75, %66, %57, %50
%82 = load i32, i32* %6
ret i32 %82
}

LLVM IR (-O2):
@AFMT_S8 = global i32 0
@AFMT_S16_BE = global i32 0
@AFMT_S16_LE = global i32 0
@AFMT_U8 = global i32 0
@AFMT_U16_BE = global i32 0
@AFMT_U16_LE = global i32 0
@.str = [15 x i8] c"/dev/sound/dsp\00"
@O_WRONLY = global i32 0
@.str.1 = [26 x i8] c"could not open dsp-device\00"
@SNDCTL_DSP_SETFMT = global i32 0
@.str.2 = [21 x i8] c"could not set format\00"
@SNDCTL_DSP_CHANNELS = global i32 0
@.str.3 = [23 x i8] c"could not set channels\00"
@SNDCTL_DSP_SPEED = global i32 0
@.str.4 = [20 x i8] c"could not set speed\00"
define i32 @setupdsp(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %3, i32* %6
store i32 %4, i32* %7
%9 = bitcast i32* %8 to i8*
%10 = icmp eq i8 %1, 0
%11 = icmp eq i8 %0, 8
br i1 %10, label %21, label %12
12: ; preds = %5
br i1 %11, label %13, label %15
13: ; preds = %12
%14 = load i32, i32* @AFMT_S8
store i32 %14, i32* %8
br label %30
15: ; preds = %12
%16 = icmp eq i8 %2, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = load i32, i32* @AFMT_S16_BE
store i32 %18, i32* %8
br label %30
19: ; preds = %15
%20 = load i32, i32* @AFMT_S16_LE
store i32 %20, i32* %8
br label %30
21: ; preds = %5
br i1 %11, label %22, label %24
22: ; preds = %21
%23 = load i32, i32* @AFMT_U8
store i32 %23, i32* %8
br label %30
24: ; preds = %21
%25 = icmp eq i8 %2, 0
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = load i32, i32* @AFMT_U16_BE
store i32 %27, i32* %8
br label %30
28: ; preds = %24
%29 = load i32, i32* @AFMT_U16_LE
store i32 %29, i32* %8
br label %30
30: ; preds = %22, %28, %26, %13, %19, %17
%31 = load i32, i32* @O_WRONLY
%32 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %57
36: ; preds = %30
%37 = load i32, i32* @SNDCTL_DSP_SETFMT
%38 = call i32 (i32, i32, ...) @ioctl(i32 %32, i32 %37, i32* %8)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @close(i32 %32)
br label %57
43: ; preds = %36
%44 = load i32, i32* @SNDCTL_DSP_CHANNELS
%45 = call i32 (i32, i32, ...) @ioctl(i32 %32, i32 %44, i32* %7)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @close(i32 %32)
br label %57
50: ; preds = %43
%51 = load i32, i32* @SNDCTL_DSP_SPEED
%52 = call i32 (i32, i32, ...) @ioctl(i32 %32, i32 %51, i32* %6)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @close(i32 %32)
br label %57
57: ; preds = %50, %54, %47, %40, %34
%58 = phi i32 [ -1, %34 ], [ -1, %40 ], [ -1, %47 ], [ -1, %54 ], [ %32, %50 ]
ret i32 %58
}