#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 */
struct mixer_ctl {
  int dummy;
};
struct mixer {
  int dummy;
};
typedef int /*<<< orphan*/ argv;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ errno;
struct mixer_ctl *get_ctl(struct mixer *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ mixer_close_legacy(struct mixer *);
int /*<<< orphan*/ mixer_ctl_print(struct mixer_ctl *);
int mixer_ctl_select(struct mixer_ctl *, char *);
int mixer_ctl_set_int(struct mixer_ctl *, int);
int /*<<< orphan*/ mixer_dump(struct mixer *);
struct mixer *mixer_open_legacy(int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  struct mixer *mixer;
  struct mixer_ctl *ctl;
  int card = 0;
  int r, i, c;
  for (i = 0; i < argc; i++) {
    if ((strncmp(argv[i], "-c", sizeof(argv[i])) == 0) ||
        (strncmp(argv[i], "-card", sizeof(argv[i])) == 0)) {
      i++;
      if (i >= argc) {
        argc -= 1;
        argv += 1;
        break;
      }
      card = atoi(argv[i]);
      argc -= 2;
      argv += 2;
      break;
    }
  }
  printf("Card:%i\n", card);
  mixer = mixer_open_legacy(card);
  if (!mixer)
    return -1;
  if (argc == 1) {
    mixer_dump(mixer);
    return 0;
  }
  ctl = get_ctl(mixer, argv[1]);
  argc -= 2;
  argv += 2;
  if (!ctl) {
    printf("can't find control\n");
    return -1;
  }
  if (argc) {
    if (isdigit(argv[0][0]))
      r = mixer_ctl_set_int(ctl, atoi(argv[0]));
    else
      r = mixer_ctl_select(ctl, argv[0]);
    if (r)
      printf("oops: %s\n", strerror(errno));
  }
  mixer_ctl_print(ctl);
  mixer_close_legacy(mixer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ae <main+0xee>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     123e <main+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    129b <main+0xdb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     126d <main+0xad>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    12ae <main+0xee>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    12ae <main+0xee>
jmp    12a0 <main+0xe0>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e4 <main+0x24>
mov    -0x24(%rbp),%esi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%edi
call   10d0 <mixer_open_legacy@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12e2 <main+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f4 <main+0x234>
cmpl   $0x1,-0x8(%rbp)
jne    1301 <main+0x141>
mov    -0x18(%rbp),%rdi
call   1080 <mixer_dump@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f4 <main+0x234>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10e0 <get_ctl@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1350 <main+0x190>
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f4 <main+0x234>
cmpl   $0x0,-0x8(%rbp)
je     13db <main+0x21b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     139a <main+0x1da>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <atoi@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1050 <mixer_ctl_set_int@plt>
mov    %eax,-0x28(%rbp)
jmp    13ad <main+0x1ed>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1090 <mixer_ctl_select@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     13d6 <main+0x216>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13db <main+0x21b>
mov    -0x20(%rbp),%rdi
call   10a0 <mixer_ctl_print@plt>
mov    -0x18(%rbp),%rdi
call   1070 <mixer_close_legacy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r12d
xor    %ebp,%ebp
test   %edi,%edi
jle    1266 <main+0x96>
mov    %r12d,%r14d
neg    %r14
mov    $0x1,%ebp
lea    0xe07(%rip),%r15
lea    0xe03(%rip),%r13
mov    -0x8(%rbx,%rbp,8),%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1242 <main+0x72>
mov    -0x8(%rbx,%rbp,8),%rdi
mov    %r13,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1242 <main+0x72>
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
jne    1200 <main+0x30>
jmp    1264 <main+0x94>
cmp    %r12d,%ebp
jge    125c <main+0x8c>
mov    (%rbx,%rbp,8),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
add    $0xfffffffe,%r12d
add    $0x10,%rbx
jmp    1266 <main+0x96>
add    $0xffffffff,%r12d
add    $0x8,%rbx
xor    %ebp,%ebp
lea    0xd9c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   10e0 <mixer_open_legacy@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1314 <main+0x144>
mov    %rax,%r14
cmp    $0x1,%r12d
jne    129e <main+0xce>
mov    %r14,%rdi
call   1090 <mixer_dump@plt>
jmp    1312 <main+0x142>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   10f0 <get_ctl@plt>
test   %rax,%rax
je     1325 <main+0x155>
mov    %rax,%r15
cmp    $0x2,%r12d
je     1302 <main+0x132>
mov    0x10(%rbx),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
mov    0x10(%rbx),%rsi
test   %rax,%rax
je     1333 <main+0x163>
mov    %rsi,%rdi
call   10c0 <atoi@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <mixer_ctl_set_int@plt>
test   %eax,%eax
je     1302 <main+0x132>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd1a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   10b0 <mixer_ctl_print@plt>
mov    %r14,%rdi
call   1080 <mixer_close_legacy@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf0(%rip),%rdi
call   1050 <puts@plt>
jmp    1314 <main+0x144>
mov    %r15,%rdi
call   10a0 <mixer_ctl_select@plt>
test   %eax,%eax
jne    12e3 <main+0x113>
jmp    1302 <main+0x132>

LLVM IR (-O0):
%struct.mixer = type { i32 }
%struct.mixer_ctl = type { i32 }
@.str = [3 x i8] c"-c\00"
@.str.1 = [6 x i8] c"-card\00"
@.str.2 = [9 x i8] c"Card:%i\0A\00"
@.str.3 = [20 x i8] c"can't find control\0A\00"
@.str.4 = [10 x i8] c"oops: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.mixer*
%7 = alloca %struct.mixer_ctl*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %10
br label %12
12: ; preds = %55, %2
%13 = load i32, i32* %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %58
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%23 = icmp eq i64 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 8)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %54
32: ; preds = %24, %16
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = load i32, i32* %4
%37 = icmp sge i32 %35, %36
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i32, i32* %4
%40 = sub nsw i32 %39, 1
store i32 %40, i32* %4
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
store i8** %42, i8*** %5
br label %58
43: ; preds = %32
%44 = load i8**, i8*** %5
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %8
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 2
store i32 %51, i32* %4
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
store i8** %53, i8*** %5
br label %58
54: ; preds = %24
br label %55
55: ; preds = %54
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %12
58: ; preds = %43, %38, %12
%59 = load i32, i32* %8
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %8
%62 = call %struct.mixer* @mixer_open_legacy(i32 %61)
store %struct.mixer* %62, %struct.mixer** %6
%63 = load %struct.mixer*, %struct.mixer** %6
%64 = icmp ne %struct.mixer* %63, null
br i1 %64, label %66, label %65
65: ; preds = %58
store i32 -1, i32* %3
br label %123
66: ; preds = %58
%67 = load i32, i32* %4
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load %struct.mixer*, %struct.mixer** %6
%71 = call i32 @mixer_dump(%struct.mixer* %70)
store i32 0, i32* %3
br label %123
72: ; preds = %66
%73 = load %struct.mixer*, %struct.mixer** %6
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call %struct.mixer_ctl* @get_ctl(%struct.mixer* %73, i8* %76)
store %struct.mixer_ctl* %77, %struct.mixer_ctl** %7
%78 = load i32, i32* %4
%79 = sub nsw i32 %78, 2
store i32 %79, i32* %4
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 2
store i8** %81, i8*** %5
%82 = load %struct.mixer_ctl*, %struct.mixer_ctl** %7
%83 = icmp ne %struct.mixer_ctl* %82, null
br i1 %83, label %86, label %84
84: ; preds = %72
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %123
86: ; preds = %72
%87 = load i32, i32* %4
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %118
89: ; preds = %86
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 0
%92 = load i8*, i8** %91
%93 = getelementptr inbounds i8, i8* %92, i64 0
%94 = load i8, i8* %93
%95 = call i64 @isdigit(i8 signext %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %104
97: ; preds = %89
%98 = load %struct.mixer_ctl*, %struct.mixer_ctl** %7
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 0
%101 = load i8*, i8** %100
%102 = call i32 @atoi(i8* %101)
%103 = call i32 @mixer_ctl_set_int(%struct.mixer_ctl* %98, i32 %102)
store i32 %103, i32* %9
br label %110
104: ; preds = %89
%105 = load %struct.mixer_ctl*, %struct.mixer_ctl** %7
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 0
%108 = load i8*, i8** %107
%109 = call i32 @mixer_ctl_select(%struct.mixer_ctl* %105, i8* %108)
store i32 %109, i32* %9
br label %110
110: ; preds = %104, %97
%111 = load i32, i32* %9
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %110
%114 = load i32, i32* @errno
%115 = call i8* @strerror(i32 %114)
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %113, %110
br label %118
118: ; preds = %117, %86
%119 = load %struct.mixer_ctl*, %struct.mixer_ctl** %7
%120 = call i32 @mixer_ctl_print(%struct.mixer_ctl* %119)
%121 = load %struct.mixer*, %struct.mixer** %6
%122 = call i32 @mixer_close_legacy(%struct.mixer* %121)
store i32 0, i32* %3
br label %123
123: ; preds = %118, %84, %69, %65
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
%struct.mixer = type { i32 }
%struct.mixer_ctl = type { i32 }
@.str = [3 x i8] c"-c\00"
@.str.1 = [6 x i8] c"-card\00"
@.str.2 = [9 x i8] c"Card:%i\0A\00"
@.str.4 = [10 x i8] c"oops: %s\0A\00"
@errno = global i32 0
@str = [19 x i8] c"can't find control\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %33
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %30
%7 = phi i64 [ 0, %4 ], [ %31, %30 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i8*, i8** %8
%14 = tail call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %12, %6
%17 = trunc i64 %7 to i32
%18 = add nuw nsw i32 %17, 1
%19 = icmp slt i32 %18, %0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = add nsw i32 %0, -1
%22 = getelementptr inbounds i8*, i8** %1, i64 1
br label %33
23: ; preds = %16
%24 = zext i32 %18 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = add nsw i32 %0, -2
%29 = getelementptr inbounds i8*, i8** %1, i64 2
br label %33
30: ; preds = %12
%31 = add nuw nsw i64 %7, 1
%32 = icmp eq i64 %31, %5
br i1 %32, label %33, label %6
33: ; preds = %30, %2, %23, %20
%34 = phi i8** [ %22, %20 ], [ %29, %23 ], [ %1, %2 ], [ %1, %30 ]
%35 = phi i32 [ %21, %20 ], [ %28, %23 ], [ %0, %2 ], [ %0, %30 ]
%36 = phi i32 [ 0, %20 ], [ %27, %23 ], [ 0, %2 ], [ 0, %30 ]
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = tail call %struct.mixer* @mixer_open_legacy(i32 %36)
%39 = icmp eq %struct.mixer* %38, null
br i1 %39, label %75, label %40
40: ; preds = %33
%41 = icmp eq i32 %35, 1
br i1 %41, label %42, label %44
42: ; preds = %40
%43 = tail call i32 @mixer_dump(%struct.mixer* %38)
br label %75
44: ; preds = %40
%45 = getelementptr inbounds i8*, i8** %34, i64 1
%46 = load i8*, i8** %45
%47 = tail call %struct.mixer_ctl* @get_ctl(%struct.mixer* %38, i8* %46)
%48 = getelementptr inbounds i8*, i8** %34, i64 2
%49 = icmp eq %struct.mixer_ctl* %47, null
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %75
52: ; preds = %44
%53 = icmp eq i32 %35, 2
br i1 %53, label %72, label %54
54: ; preds = %52
%55 = load i8*, i8** %48
%56 = load i8, i8* %55
%57 = tail call i64 @isdigit(i8 signext %56)
%58 = icmp eq i64 %57, 0
%59 = load i8*, i8** %48
br i1 %58, label %63, label %60
60: ; preds = %54
%61 = tail call i32 @atoi(i8* %59)
%62 = tail call i32 @mixer_ctl_set_int(%struct.mixer_ctl* %47, i32 %61)
br label %65
63: ; preds = %54
%64 = tail call i32 @mixer_ctl_select(%struct.mixer_ctl* %47, i8* %59)
br label %65
65: ; preds = %63, %60
%66 = phi i32 [ %62, %60 ], [ %64, %63 ]
%67 = icmp eq i32 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %65
%69 = load i32, i32* @errno
%70 = tail call i8* @strerror(i32 %69)
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %65, %68, %52
%73 = tail call i32 @mixer_ctl_print(%struct.mixer_ctl* %47)
%74 = tail call i32 @mixer_close_legacy(%struct.mixer* %38)
br label %75
75: ; preds = %33, %72, %50, %42
%76 = phi i32 [ 0, %42 ], [ 0, %72 ], [ -1, %50 ], [ -1, %33 ]
ret i32 %76
}