#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 */
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ exit_error(char *);
int /*<<< orphan*/ *optarg;
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strlen(char *);
int strtol(int /*<<< orphan*/ *, char **, int);
void opt_set(int *var, char *name) {
  char *endptr;
  if (optarg != NULL)
    *var = strtol(optarg, &endptr, 10);
  if (!endptr || *endptr != '\0' || !optarg) {
    char msg[strlen("invalid \n") + strlen(name) + 1];
    snprintf(msg, sizeof(msg), "invalid %s\n", name);
    exit_error(msg);
  }
}


x86 assembly (clang, -O0):
<opt_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea1(%rip),%rax
cmpq   $0x0,(%rax)
je     1181 <opt_set+0x41>
mov    0x2e90(%rip),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11ad <opt_set+0x6d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ad <opt_set+0x6d>
mov    0x2e55(%rip),%rax
cmpq   $0x0,(%rax)
jne    1215 <opt_set+0xd5>
lea    0xe4c(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x20(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe0a(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <exit_error@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_set>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea1(%rip),%r15
mov    (%r15),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,(%rbx)
mov    -0x20(%rbp),%rax
test   %rax,%rax
je     117e <opt_set+0x3e>
cmpb   $0x0,(%rax)
jne    117e <opt_set+0x3e>
cmpq   $0x0,(%r15)
jne    11ba <opt_set+0x7a>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r15
lea    0xa(%rax),%esi
mov    %rsp,%rbx
add    $0x19,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe5c(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <exit_error@plt>
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@optarg = global i32* null
@.str = [10 x i8] c"invalid \0A\00"
@.str.1 = [12 x i8] c"invalid %s\0A\00"
define void @opt_set(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = load i32*, i32** @optarg
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32*, i32** @optarg
%12 = call i32 @strtol(i32* %11, i8** %5, i32 10)
%13 = load i32*, i32** %3
store i32 %12, i32* %13
br label %14
14: ; preds = %10, %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32*, i32** @optarg
%24 = icmp ne i32* %23, null
br i1 %24, label %38, label %25
25: ; preds = %22, %17, %14
%26 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %26, %28
%30 = add nsw i64 %29, 1
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %6
%32 = alloca i8, i64 %30
store i64 %30, i64* %7
%33 = trunc i64 %30 to i32
%34 = load i8*, i8** %4
%35 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit_error(i8* %32)
%37 = load i8*, i8** %6
br label %38
38: ; preds = %25, %22
ret void
}

LLVM IR (-O2):
@optarg = global i32* null
@.str.1 = [12 x i8] c"invalid %s\0A\00"
define void @opt_set(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32*, i32** @optarg
%6 = call i32 @strtol(i32* %5, i8** %3, i32 10)
store i32 %6, i32* %0
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
%12 = load i32*, i32** @optarg
%13 = icmp ne i32* %12, null
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %23, label %15
15: ; preds = %9, %2
%16 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%17 = add nsw i64 %16, 10
%18 = tail call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = trunc i64 %17 to i32
%21 = call i32 @snprintf(i8* %19, i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%22 = call i32 @exit_error(i8* %19)
br label %23
23: ; preds = %9, %15
ret void
}