#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 */
#define EINVAL 130
#define ENODEV 129
#define ENOENT 128
int dasd_reset_chpid(char *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error_print(char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int disk_reset_chpid(char *device, char *chpid) {
  int rc;
  if (chpid)
    printf("Resetting chpid %s for device <%s>...\n", chpid, device);
  else
    printf("Resetting all chpids for device <%s>...\n", device);
  rc = dasd_reset_chpid(device, chpid);
  switch (rc) {
  case 0:
    printf("Done.\n");
    return 0;
  case ENODEV:
    error_print("%s: %s", device, strerror(errno));
    break;
  case EINVAL:
    error_print("%s: Could not reset chpid %s: Invalid CHPID", device, chpid);
    break;
  case ENOENT:
    error_print("%s: Could not reset chpid %s: CHPID not defined for device",
                device, chpid);
    break;
  default:
    error_print("%s: Could not reset chpid %s", device, chpid);
    break;
  }
  return -1;
}


x86 assembly (clang, -O0):
<disk_reset_chpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1176 <disk_reset_chpid+0x36>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1188 <disk_reset_chpid+0x48>
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dasd_reset_chpid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     11e4 <disk_reset_chpid+0xa4>
jmp    11ab <disk_reset_chpid+0x6b>
mov    -0x20(%rbp),%eax
sub    $0x80,%eax
je     1245 <disk_reset_chpid+0x105>
jmp    11be <disk_reset_chpid+0x7e>
mov    -0x20(%rbp),%eax
sub    $0x81,%eax
je     11fe <disk_reset_chpid+0xbe>
jmp    11d1 <disk_reset_chpid+0x91>
mov    -0x20(%rbp),%eax
sub    $0x82,%eax
je     122c <disk_reset_chpid+0xec>
jmp    125e <disk_reset_chpid+0x11e>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <disk_reset_chpid+0x139>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe35(%rip),%rdi
call   1040 <error_print@plt>
jmp    1272 <disk_reset_chpid+0x132>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe23(%rip),%rdi
call   1040 <error_print@plt>
jmp    1272 <disk_reset_chpid+0x132>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rdi
call   1040 <error_print@plt>
jmp    1272 <disk_reset_chpid+0x132>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe58(%rip),%rdi
call   1040 <error_print@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_reset_chpid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     1175 <disk_reset_chpid+0x25>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1186 <disk_reset_chpid+0x36>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dasd_reset_chpid@plt>
cmp    $0x80,%eax
jg     11ac <disk_reset_chpid+0x5c>
test   %eax,%eax
je     11d2 <disk_reset_chpid+0x82>
cmp    $0x80,%eax
jne    11c3 <disk_reset_chpid+0x73>
lea    0xed9(%rip),%rdi
jmp    11ca <disk_reset_chpid+0x7a>
cmp    $0x81,%eax
je     11e2 <disk_reset_chpid+0x92>
cmp    $0x82,%eax
jne    11c3 <disk_reset_chpid+0x73>
lea    0xe96(%rip),%rdi
jmp    11ca <disk_reset_chpid+0x7a>
lea    0xef4(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
jmp    11fd <disk_reset_chpid+0xad>
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1207 <disk_reset_chpid+0xb7>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <error_print@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Resetting chpid %s for device <%s>...\0A\00"
@.str.1 = [41 x i8] c"Resetting all chpids for device <%s>...\0A\00"
@.str.2 = [7 x i8] c"Done.\0A\00"
@.str.3 = [7 x i8] c"%s: %s\00"
@errno = global i32 0
@.str.4 = [44 x i8] c"%s: Could not reset chpid %s: Invalid CHPID\00"
@.str.5 = [59 x i8] c"%s: Could not reset chpid %s: CHPID not defined for device\00"
@.str.6 = [29 x i8] c"%s: Could not reset chpid %s\00"
define i32 @disk_reset_chpid(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
br label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @dasd_reset_chpid(i8* %17, i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
switch i32 %20, label %36 [
i32 0, label %21
i32 129, label %23
i32 130, label %28
i32 128, label %32
]
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %41
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @error_print(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* %26)
br label %40
28: ; preds = %16
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 @error_print(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %29, i8* %30)
br label %40
32: ; preds = %16
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = call i32 @error_print(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* %34)
br label %40
36: ; preds = %16
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i32 @error_print(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %37, i8* %38)
br label %40
40: ; preds = %36, %32, %28, %23
store i32 -1, i32* %3
br label %41
41: ; preds = %40, %21
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [39 x i8] c"Resetting chpid %s for device <%s>...\0A\00"
@.str.1 = [41 x i8] c"Resetting all chpids for device <%s>...\0A\00"
@.str.3 = [7 x i8] c"%s: %s\00"
@errno = global i32 0
@.str.4 = [44 x i8] c"%s: Could not reset chpid %s: Invalid CHPID\00"
@.str.5 = [59 x i8] c"%s: Could not reset chpid %s: CHPID not defined for device\00"
@.str.6 = [29 x i8] c"%s: Could not reset chpid %s\00"
@str = [6 x i8] c"Done.\00"
define i32 @disk_reset_chpid(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
br label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @dasd_reset_chpid(i8* %0, i8* %1)
switch i32 %9, label %20 [
i32 0, label %10
i32 129, label %12
i32 130, label %16
i32 128, label %18
]
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %22
12: ; preds = %8
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @error_print(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %14)
br label %22
16: ; preds = %8
%17 = tail call i32 @error_print(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1)
br label %22
18: ; preds = %8
%19 = tail call i32 @error_print(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
br label %22
20: ; preds = %8
%21 = tail call i32 @error_print(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %1)
br label %22
22: ; preds = %12, %16, %18, %20, %10
%23 = phi i32 [ 0, %10 ], [ -1, %20 ], [ -1, %18 ], [ -1, %16 ], [ -1, %12 ]
ret i32 %23
}