#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*/ USBDEVFS_CLAIMINTERFACE;
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, int, ...);
char *strerror(int);
void claim_some_intf(int fd) {
  int i = 0;
  for (i = 0; i < 4; i++) {
    int res = ioctl(fd, USBDEVFS_CLAIMINTERFACE, &i);
    if (!res) {
      printf("OK: claimed if %d\n", i);
    } else {
      printf("ERROR claiming if %d (%d - %s)\n", i, -res, strerror(-res));
    }
  }
}


x86 assembly (clang, -O0):
<claim_some_intf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11cd <claim_some_intf+0x9d>
mov    -0x4(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    118b <claim_some_intf+0x5b>
mov    -0x8(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ba <claim_some_intf+0x8a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
xor    %edi,%edi
sub    -0xc(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    %rax,%rcx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <claim_some_intf+0x8f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <claim_some_intf+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<claim_some_intf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
movl   $0x0,0x4(%rsp)
mov    0x2e93(%rip),%r15
lea    0x4(%rsp),%r14
lea    0xeba(%rip),%r12
jmp    118c <claim_some_intf+0x5c>
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebx
neg    %ebx
mov    %ebx,%edi
call   1050 <strerror@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x3,%eax
jge    11b4 <claim_some_intf+0x84>
mov    (%r15),%esi
mov    %r13d,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
mov    0x4(%rsp),%ebp
test   %eax,%eax
jne    1160 <claim_some_intf+0x30>
lea    0xe57(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    117c <claim_some_intf+0x4c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@USBDEVFS_CLAIMINTERFACE = global i32 0
@.str = [19 x i8] c"OK: claimed if %d\0A\00"
@.str.1 = [32 x i8] c"ERROR claiming if %d (%d - %s)\0A\00"
define void @claim_some_intf(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %3
br label %5
5: ; preds = %26, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 4
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* @USBDEVFS_CLAIMINTERFACE
%11 = call i32 @ioctl(i32 %9, i32 %10, i32* %3)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* %3
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %25
17: ; preds = %8
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 0, %19
%21 = load i32, i32* %4
%22 = sub nsw i32 0, %21
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %20, i8* %23)
br label %25
25: ; preds = %17, %14
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %5
29: ; preds = %5
ret void
}

LLVM IR (-O2):
@USBDEVFS_CLAIMINTERFACE = global i32 0
@.str = [19 x i8] c"OK: claimed if %d\0A\00"
@.str.1 = [32 x i8] c"ERROR claiming if %d (%d - %s)\0A\00"
define void @claim_some_intf(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %1, %15
%5 = load i32, i32* @USBDEVFS_CLAIMINTERFACE
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %2)
%7 = icmp eq i32 %6, 0
%8 = load i32, i32* %2
br i1 %7, label %9, label %11
9: ; preds = %4
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %15
11: ; preds = %4
%12 = sub nsw i32 0, %6
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %12, i8* %13)
br label %15
15: ; preds = %11, %9
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
%18 = icmp slt i32 %16, 3
br i1 %18, label %4, label %19
19: ; preds = %15
ret void
}