#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ ring_bell(int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  if (argc < 3) {
    perror("Usage : beeper <frequence> <duration> ... ");
    return EXIT_FAILURE;
  } else {
    int i = 1;
    while (i + 1 < argc) {
      int frequence = atoi(argv[i++]);
      int duration = atoi(argv[i++]);
      ring_bell(frequence);
      usleep(1000 * duration);
    }
    ring_bell(0);
    return EXIT_SUCCESS;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    117d <main+0x3d>
lea    0xe99(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <main+0xbb>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    11e8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <ring_bell@plt>
imul   $0x3e8,-0x1c(%rbp),%edi
call   1060 <usleep@plt>
jmp    1184 <main+0x44>
xor    %edi,%edi
call   1050 <ring_bell@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x3,%edi
jl     11ad <main+0x6d>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
mov    -0x8(%r15,%rbp,8),%rdi
call   1040 <atoi@plt>
mov    %eax,%r12d
mov    (%r15,%rbp,8),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
mov    %r12d,%edi
call   1050 <ring_bell@plt>
imul   $0x3e8,%ebx,%edi
call   1060 <usleep@plt>
add    $0x2,%rbp
cmp    %r14d,%ebp
jl     1160 <main+0x20>
xor    %edi,%edi
call   1050 <ring_bell@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4c(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e20(%rip),%rax
jmp    11a2 <main+0x62>

LLVM IR (-O0):
@.str = [43 x i8] c"Usage : beeper <frequence> <duration> ... \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %43
14: ; preds = %2
store i32 1, i32* %6
br label %15
15: ; preds = %20, %14
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i8**, i8*** %5
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %8
%35 = load i32, i32* %7
%36 = call i32 @ring_bell(i32 %35)
%37 = load i32, i32* %8
%38 = mul nsw i32 1000, %37
%39 = call i32 @usleep(i32 %38)
br label %15
40: ; preds = %15
%41 = call i32 @ring_bell(i32 0)
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %43
43: ; preds = %40, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [43 x i8] c"Usage : beeper <frequence> <duration> ... \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %25
6: ; preds = %2, %6
%7 = phi i64 [ %12, %6 ], [ 1, %2 ]
%8 = phi i64 [ %19, %6 ], [ 2, %2 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = add nuw i64 %7, 2
%13 = getelementptr inbounds i8*, i8** %1, i64 %8
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 @ring_bell(i32 %11)
%17 = mul nsw i32 %15, 1000
%18 = tail call i32 @usleep(i32 %17)
%19 = add i64 %8, 2
%20 = trunc i64 %7 to i32
%21 = add i32 %20, 3
%22 = icmp slt i32 %21, %0
br i1 %22, label %6, label %23
23: ; preds = %6
%24 = tail call i32 @ring_bell(i32 0)
br label %25
25: ; preds = %23, %4
%26 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %23 ]
%27 = load i32, i32* %26
ret i32 %27
}