#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*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int);
int read_integer_switch(const char *arg, int argc, char **argv, int *out) {
  int ok = 1;
  if (argc == 0) {
    fprintf(stderr, "Error: Expected value following %s\n", arg);
    ok = 0;
  } else {
    char *endptr = 0;
    *out = strtol(argv[0], &endptr, 10);
    if (endptr == 0 || *endptr != 0) {
      fprintf(stderr, "Error: Invalid value %s following %s\n", argv[0], arg);
      ok = 0;
    }
  }
  return ok;
}


x86 assembly (clang, -O0):
<read_integer_switch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116f <read_integer_switch+0x4f>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
jmp    11dd <read_integer_switch+0xbd>
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     11af <read_integer_switch+0x8f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d8 <read_integer_switch+0xb8>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
jmp    11dd <read_integer_switch+0xbd>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_integer_switch>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %esi,%esi
je     1184 <read_integer_switch+0x64>
mov    %rcx,%r15
mov    %rdx,%rbx
movq   $0x0,0x8(%rsp)
mov    (%rdx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r15)
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1163 <read_integer_switch+0x43>
cmpb   $0x0,(%rax)
je     11a2 <read_integer_switch+0x82>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xeae(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a7 <read_integer_switch+0x87>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a7 <read_integer_switch+0x87>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Error: Expected value following %s\0A\00"
@.str.1 = [38 x i8] c"Error: Invalid value %s following %s\0A\00"
define i32 @read_integer_switch(i8* %0, i32 %1, i8** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
store i32 1, i32* %9
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 0, i32* %9
br label %38
17: ; preds = %4
store i8* null, i8** %10
%18 = load i8**, i8*** %7
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @strtol(i8* %20, i8** %10, i32 10)
%22 = load i32*, i32** %8
store i32 %21, i32* %22
%23 = load i8*, i8** %10
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %17
%26 = load i8*, i8** %10
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %25, %17
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %7
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i8*, i8** %5
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
store i32 0, i32* %9
br label %37
37: ; preds = %30, %25
br label %38
38: ; preds = %37, %13
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Error: Expected value following %s\0A\00"
@.str.1 = [38 x i8] c"Error: Invalid value %s following %s\0A\00"
define i32 @read_integer_switch(i8* %0, i32 %1, i8** nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
10: ; preds = %4
%11 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%12 = load i8*, i8** %2
%13 = call i32 @strtol(i8* %12, i8** %5, i32 10)
store i32 %13, i32* %3
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16, %10
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %0)
br label %23
23: ; preds = %19, %16
%24 = phi i32 [ 0, %19 ], [ 1, %16 ]
br label %25
25: ; preds = %23, %7
%26 = phi i32 [ 0, %7 ], [ %24, %23 ]
ret i32 %26
}